minihippo / LeetCode

Recording

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LeetCode

The reposity is for recording submissions in LeetCode. Programing language is java and Scala.

Updating...

Array

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

About

Recording


Languages

Language:Java 68.5%Language:Scala 31.5%