LeetCode Solutions | 101 - 200
110. Balanced Binary Tree
just do it
131. Palindrome Partitioning
brute force recursion
134. Gas Station
find the travel length l
of starting point i
, the travel length of starting point in [i .. i + j]
are no bigger than l
if the total gas is greater than costs, there must be a starting point. start i
and start point from 0, each time curr
reaches a negative value, set starting point to i + 1
139. Word Break
recursion+memorization or dp
146. LRU Cache
HashMap<Key, Node>
& DoublyLinkedList<Value>
150. Evaluate Reverse Polish Notation
151. Reverse Words in a String
先反转整个字符串 in-place,再反转每个单词 in-place
162. Find Peak Element
binary search, whether m
is at a descending slope or not
163. Missing Ranges
let lo = lower - 1
initially, then compare each value with lo then update lo, finally check lo with upper
166. Fraction to Recurring Decimal
using long division(the way we do division by hand) and a hash map to check if the current numerator has once appeared, if so, we found the repeating range. the first time the current numerator is smaller than the denomenater, place the comma
167. Two Sum II - Input array is sorted
two pointers
170. Two Sum III - Data structure design
it seems that there has to be one operation's time complexity is O(n) and the other is O(1).
then it's trivial
172. Factorial Trailing Zeroes
every zero comes from factors 5 * 2, there are plenty of 2s, so the key is to find how many 5-factors.
190. Reverse Bits
get every pos using bit op then construct a new one
every time you right shift the original number, left shift the resulting number then add 1(or 0)
199. Binary Tree Right Side View
find right most of each level
200. Number of Islands
dfd || bfs
union find