Skip to content

tsupei/leetcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Leetcode

Intend to solve problems in Python3 or C.

Solved Problems

C:

  1. Swap Nodes in Pairs
  2. (important) O(n) solution is subtle. Remember it.

Python:

  1. Merge k Sorted Lists
  2. Swap Nodes in Pairs
  3. Reverse Nodes in k-Group
  4. Remove Duplicates from Sorted Array
  5. Remove Element
  6. Implement strStr()
  7. Divide Two Integers
  8. Substring with Concatenation of All Words
  9. (*a)Next Permutation
  10. Substring with Concatenation of All Words
  11. Search in Rotated Sorted Array
  12. Find First and Last Position of Element in Sorted Array
  13. Search Insert Position
  14. Valid Sudoku
  15. Sudoku Solver
  16. Count and Say
  17. Combination Sum
  18. Combination Sum II
  19. First Missing Positive
  20. Trapping Rain Water
  21. Multiply Strings
  22. Wildcard Matching
  23. Jump Game II
  24. Permutations
  25. Permutations II
  26. Rotate Image
  27. Group Anagrams
  28. Pow(x, n)
  29. N-Queens
  30. N-Queens II
  31. Maximum Subarray
  32. Spiral Matrix
  33. Jump Game
  34. Merge Intervals
  35. Insert Interval
  36. Length of Last Word
  37. Spiral Matrix II
  38. Permutation Sequence
  39. Rotate List
  40. Unique Paths
  41. Unique Paths II
  42. Minimum Path Sum

a. The difference between listA.reverse() and listA[::-1]

One Line Summary

from 2019/10/18

  1. iterate from the very last, find the second-minima
  2. (difficult)DP
  3. Two Binary Search(one for seeking pivot point)
  4. Binary Search
  5. Binary Search, or iterate from the beginning
  6. Check Row, Column, Block (Three loops)
  7. Recursive
  8. Recursive
  9. Recursive, determine the same set?
  10. Recursive, how to prevent repeated answer
  11. (difficult) Time Complexity O(n), Space Complexity O(1), use the origin matrix as an index array
  12. DP, Time Complexity O(n) ~= 3n
  13. Use array representation to do multiplication
  14. (difficult)DP,
  15. Greedy!
  16. Recursive
  17. for duplicate input, sort and targeting each unique number only once
 ^
[1,1,1,1,1,3,4]
           ^
[1,1,1,1,1,3,4]
             ^
[1,1,1,1,1,3,4]
  1. transpose and reverse
  2. sorted string, O = nmlogm, n=len(strs), m=len(str)
  3. (Not recommended) recursive
  4. 8 queens, recursive
  5. == 51
# How to allocate a 2D array in python
# The following example gives you a 3*3 array
n = 3
arr = [[0 for i in range(n)] for j in range(n)]

# How to copy a 2D array in python
cp_arr = [row[:] for row in arr]

# ps. how to copy a 1D array in python
arr = [0] * n
cp_arr = arr[:]
  1. (interesting)

    • transpose, divide and conquer, resursive
    • directly spiral iteration
  2. .= 45

  3. merge, extend the upper bound

  4. insert and merge(56.)

  5. Trival

  6. Trival

  7. Calculate fatorial

  8. Linked List

  9. Trival

  10. dp?

  11. dp?

  12. Trival

  13. Binary addition

  14. Trival but a lot of traps

  15. Binary Search

  16. Don't use recursive, try combination

=== From now on, only focus on problems whose likes more than dislikes ===

  1. Try to use less space: Optimal O(1), but mine is O(m+n)

  2. Binary Search in two dimension

  3. Trival

  4. (not-complete)

  5. Recursive, (Is there a better solution?)

  6. Recursive (faster than 71.13%)

  7. Recursive (faster than 96.68%)

  8. Trival

  9. (compare to 33) (faster than 33.34%, O(n)) Is there a O(log(n)) solution?

  10. Linked List

  11. Linked List

  12. (difficult)(Need to be recoded!) Not A very elegant solution

  13. (difficult)

  14. (Again)Partition, (using an buffer to store require space O(n), try not to use?)

  15. Replace in place. (faster than 63.xx%)

  16. Recursive

  17. pick, reverse, and concatenate

  18. Calculate all combination First

  19. (Trival) What is inorder(LVR) / postorder(LRV) / preorder(VLR)

  20. (faster than 94.83%) Similar to 96. Recursive

  21. (Trival) Divide and Conquer

  22. (difficult, important) dp, manage 2D array

  23. (important) Validate BST

  24. (slow) simply recursively compare

  25. (faster than 8.18%) simple recursion (faster than 81.35%) loop solution

  26. (faster than 97.37%) similar to 102.

  27. (faster than 93.69%) simple recursion

  28. (faster than 9.18%) divide and conquer, recursion (Find root node)

  29. (faster than 8.03%) similar to 105.

  30. (faster than 6.35%) divide and conquer

Updated on 2019/12/1

About

Record for solving Leetcode Problems

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published