The reposity is for recording submissions in LeetCode. Programing language is java and Scala.
Updating...
- TwoSum
map.containsKey()
- Remove Duplicates From Sorted Array
- two pointers
- Remove Element
- Search Insert Position
- two pointers,binary search
- Maximum Subarray
- Plus One
- immutable array of integer will be intialized with 0
- Merge Sorted Array
- Pascal's Triangle
scala: unaccepted maybe linkedlist is the type to solve the problem - Pascal's Triangle2
scala:unaccepted - Best Time to Buy and Sell Stock
- CQ
- Kadane's Algorithm: maximum subarray problem
- Best Time to Buy and Sell Stock2
- Peak Valley Approach
- greedy algorithm is slower than the other solution
- Two Sum2
- two pointers
- binary search : O(logn),defeat 99%
- Majority Element
- Mroove voting Algorithm
- for extension: icebrug, element appears more than k times
- Rotate Array
bad solution- extra space;three times reversal;reserve
- I consider that queue is the best data structure to solve the problem
- Contains Duplicate
scala:unaccepted- byte array: most fast
- Contains Duplicate
scala:unaccepted- set and sliding window
- Move Zeroes
- two pointers
- while is faster than for loop
- Third Maximum Number
- the normal way O(logn)
- priority queue: O(nlogn)
- Find All Numbers Disappeared in an Array
scala:unaccepted - Max Consecutive Ones
- concise way has long runtime
- K-diff pairs in an Array
- sort then two pointers
- map: map.entry map.keySet()
- Array Partition
- sort then ... nlogn
- bucket sort, n. beats 98.97%. faster
- Reshape the Matrix
- common way
- Container With Most Water
- two pointers
- Math.max/min runtime seems slower than direct comparison