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.
[2,3,4], the median is
[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.
- findMedian() -> 1.5
- findMedian() -> 2
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.
- 133 Clone Graph
- 207 Course Schedule
- 210 Course Schedule II
- 3 Longest Substring Without Repeating Characters
- 160 Intersection of Two Linked Lists
- 202 Happy Number
- 242 Valid Anagram
- 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
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.
["This", "is", "an", "example", "of", "text", "justification."]
Return the formatted lines as:
“This is an”,
“example of text”,
Note: Each word is guaranteed not to exceed L in length.
leetcode Simplify Path
Given an absolute path for a file (Unix-style), simplify it.
- 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
In this case, you should ignore redundant slashes and return