## 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:

• findMedian() -> 1.5
• 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.

• push
• pop
• 堆的创建及其他应用

## leetcode Graph 图论

• 133 Clone Graph
• 207 Course Schedule
• 210 Course Schedule II

## leetcode hashtable

• hashtable简洁即实现
• Longest Substring Without Repeating Characters
• 160 Intersection of Two Linked Lists
• 202 Happy Number
• 242 Valid Anagram

## leetcode Best Time to Buy and Sell Stock

• 121 Best Time to Buy and Sell Stock
• 122 Best Time to Buy and Sell Stock II
• 123 Best Time to Buy and Sell Stock III
• 188 Best Time to Buy and Sell Stock IV
• 714. Best Time to Buy and Sell Stock with Transaction Fee

RSA的大整数分解。

## leetcode Text Justification

### leetcode Text Justification

Given an array of words and a length L, format the text such that each line has exactly L characters and is fully (left and right) justified.

You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces `' '` when necessary so that each line has exactlyL characters.

Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line do not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.

For the last line of text, it should be left justified and no extra space is inserted between words.

For example,
words: `["This", "is", "an", "example", "of", "text", "justification."]`
L: `16`.

Return the formatted lines as:

[
“This is an”,
“example of text”,
“justification. ”
]

Note: Each word is guaranteed not to exceed L in length.

## leetcode Simplify Path

### leetcode Simplify Path

Given an absolute path for a file (Unix-style), simplify it.

For example,
path = `"/home/"`, => `"/home"`
path = `"/a/./b/../../c/"`, => `"/c"`

Corner Cases:

• Did you consider the case where path = `"/../"`?
In this case, you should return `"/"`.
• Another corner case is the path might contain multiple slashes `'/'` together, such as `"/home//foo/"`.
In this case, you should ignore redundant slashes and return `"/home/foo"`.