今天安装了Gephi后，发现打开就显示下欢迎界面，就消失了。

# Month: October 2015

## leetcode Find Median from Data Stream

## leetcode Find Median from Data Stream

Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.

Examples:

`[2,3,4]`

, the median is`3`

`[2,3]`

, the median is`(2 + 3) / 2 = 2.5`

Design a data structure that supports the following two operations:

- void addNum(int num) – Add a integer number from the data stream to the data structure.
- double findMedian() – Return the median of all elements so far.
For example:

- add(1)
- add(2)
- findMedian() -> 1.5
- add(3)
- findMedian() -> 2

## leetcode Nim Game

## leetcode Nim Game

You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove the stones.

Both of you are very clever and have optimal strategies for the game. Write a function to determine whether you can win the game given the number of stones in the heap.

For example, if there are 4 stones in the heap, then you will never win the game: no matter 1, 2, or 3 stones you remove, the last stone will always be removed by your friend.

## leetcode Word Pattern

## leetcode Word Pattern

Given a

`pattern`

and a string`str`

, find if`str`

follows the same pattern.

Examples:

- pattern =
`"abba"`

, str =`"dog cat cat dog"`

should return true.- pattern =
`"abba"`

, str =`"dog cat cat fish"`

should return false.- pattern =
`"aaaa"`

, str =`"dog cat cat dog"`

should return false.- pattern =
`"abba"`

, str =`"dog dog dog dog"`

should return false.

Notes:

- Both
`pattern`

and`str`

contains only lowercase alphabetical letters.- Both
`pattern`

and`str`

do not have leading or trailing spaces.- Each word in
`str`

is separated by a single space.- Each letter in
`pattern`

must map to a word with length that is at least 1.

## leetcode Find the Duplicate Number

## leetcode Find the Duplicate Number

Given an array

numscontainingn+ 1 integers where each integer is between 1 andn(inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one.

Note:

- You
must notmodify the array (assume the array is read only).- You must use only constant,
O(1) extra space.- Your runtime complexity should be less than
`O(n`

.^{2})- There is only one duplicate number in the array, but it could be repeated more than once.

## leetcode Game of Life

## leetcode Game of Life

According to the Wikipedia’s article: “The

Game of Life, also known simply asLife, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.”Given a

boardwithmbyncells, each cell has an initial statelive(1) ordead(0). Each cell interacts with its eight neighbors (horizontal, vertical, diagonal) using the following four rules (taken from the above Wikipedia article):

- Any live cell with fewer than two live neighbors dies, as if caused by under-population.
- Any live cell with two or three live neighbors lives on to the next generation.
- Any live cell with more than three live neighbors dies, as if by over-population..
- Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.
Write a function to compute the next state (after one update) of the board given its current state.

Follow up:

- Could you solve it in-place? Remember that the board needs to be updated at the same time: You cannot update some cells first and then use their updated values to update other cells.
- In this question, we represent the board using a 2D array. In principle, the board is infinite, which would cause problems when the active area encroaches the border of the array. How would you address these problems?