Skip to content

tuouo/leetcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 

Repository files navigation

The Python 3 journey of leetcode Problems Algorithms
You may meet some problems on the way, and it(Problems you may face to) may be helpful.

Here is the classification of free questions.

Algorithms

Array

No. Title Difficulty Time Space Solution Runtime Tip
1 Two Sum Easy O(n) O(n) 85.53(42ms,170626) set
4 Median of Two Sorted Arrays Hard O(log(m+n)) O(1) 78.16(99ms, 1706) find kth
11 Container With Most Water Medium O(n) O(1) 85.39(69ms, 1705) from limit
15 3Sum Medium O(n^2) O(1) 97.21(848ms, 1705) sorted, meet
16 3Sum Closest Medium O(n^2) O(1) 56.32(145ms, 1705) sorted, meet
18 4Sum Medium O(n^3) O(1) 86.12(132ms, 1703) 3sum
26 Remove Duplicates from Sorted Array Easy O(n) O(1) 77.68(79ms,170801)
27 Remove Element Easy O(n) O(1) 67.84(45ms, 1703)
31 Next Permutation Medium O(n) O(1) 56.61(62ms, 1703)
33 Search in Rotated Sorted Array Medium O(logn) O(1) 21.87(58ms, 1703) Binary Search
34 Search for a Range Medium O(logn) O(1) 73.72(45ms,170620) Binary Search left, then right
35 Search Insert Position Easy O(logn) O(1) 82.93(39ms,170620) check range & bisect
39 Combination Sum Medium O(k*n^k) O(k^2) 99.81(72ms,170625) backtracking, check target
40 Combination Sum II Medium O(k*n^k) O(k^2) 93.17(65ms,170626)
41 First Missing Positive Hard O(n) O(1) 72.06(42ms,170627) reset x to position x
42 Trapping Rain Water Hard O(n) O(n) 72.91(52ms,170628) PEAK peak PEAK
45 Jump Game II Hard O(n) O(n) 98.24(49ms,170705)
48 Rotate Image Medium O(n^2) O(1) 61(45ms,170704)
53 Maximum Subarray Medium O(n) O(1) 88.17(45ms,170719)
54 Spiral Matrix Medium O(mn) O(mn) 82.77(32ms,170720)
55 Jump Game Medium O(m) O(1) 63.92(52ms,170723)
56 Merge Intervals Medium O(m) O(1) 92.09(72ms,170726)
57 Insert Interval Hard O(m) O(1) 98.84(62ms,170727) leetcode may give wrong Runtime
62 Unique Paths Medium O(1) O(1) 76.22(32ms,1705) directly
63 Unique Paths II Medium O(mn) O(m) 51,91(39ms,170815)
64 Minimum Path Sum Medium O(mn) O(m) 66.04(58ms,1705)
66 Plus One Easy O(n) O(1) 32.37(42ms,1705)

Hash Table

No. Title Difficulty Time Space Solution Runtime Tip
1 Two Sum Easy O(n) O(n) 85.53(42ms,170626) set
3 Longest Substring Without Repeating Characters Medium O(n) O(n) 88.87(89ms, 1704) between the same
18 4Sum Medium O(n^3) O(1) 86.12(132ms, 1703) 3sum
30 Substring with Concatenation of All Words Hard O(mnk) O(nk) 70.72(98ms,170620) use find info
36 Valid Sudoku Medium O(9Ă—9) O(9Ă—9) 75.42(76ms,170623) many ways to check
37 Sudoku Solver Hard O((9!)^9) O(1) 90.91(72ms,170623) check then put, if wrong backtrack. Or play like human
49 Group Anagrams Medium O(mn) O(mn) 90.95(212ms,170711) frequency with hash

Linked List

No. Title Difficulty Time Space Solution Runtime Tip
2 Add Two Numbers Medium O(n) O(1) 61.77(135ms,1704)
19 Remove Nth Node From End of List Easy O(n) O(1) 93.74(42ms,170623)
21 Merge Two Sorted Lists Easy O(n) O(1) 73.67(52ms, 1705)
23 Merge k Sorted Lists Hard O(nlogk) O(1) 98.15(105ms, 1703)
24 Swap Nodes in Pairs Easy O(n) O(1) 60.77(42ms, 1703)
25 Reverse Nodes in k-Group Hard O(n) O(1) 73.50(72ms,170605)
61 Rotate List Medium O(n) O(1) 83.99(45ms,170811)

Math

No. Title Difficulty Time Space Solution Runtime Tip
2 Add Two Numbers Medium O(n) O(1) 61.77(135ms,1704)
7 Reverse Integer Easy O(n) O(1) 34.12(66ms, 1703)
8 String to Integer (atoi) Medium O(n) O(1) 44.69(78ms, 1704)
9 Palindrome Number Easy O(n) O(1) 80.74(216ms, 1704)
12 Integer to Roman Medium O(n) O(1) 90.62(105ms, 1705) directly
13 Roman to Integer Medium O(n) O(1) 88.58(132ms, 1705) lambda
29 Divide Two Integers Medium O(m/n) O(1) 33.58(68ms, 1703)
43 Multiply Strings Medium O(m*n) O(m+n) 94.76(49ms,1704) / 76.65(168ms,170629) carry, once
50 Pow(x, n) Medium O(m*n) O(m+n) 74.33(39ms, 1705)
60 Permutation Sequence Medium O(n) O(n) 33.52(45ms, 1705)
65 Valid Number Hard O(1) O(1) 37.72(62ms,170729)
66 Plus One Easy O(n) O(1) 32.37(42ms,1705)
67 Add Binary Easy O(1) O(1) 82.49(42ms,1705)
69 Sqrt(x) Easy O(1) O(1) 77.55(42ms,1705) sqrtx

Two Pointers

No. Title Difficulty Time Space Solution Runtime Tip
3 Longest Substring Without Repeating Characters Medium O(n) O(n) 88.87(89ms, 1704) between the same
11 Container With Most Water Medium O(n) O(1) 85.39(69ms, 1705) from limit
15 3Sum Medium O(n^2) O(1) 97.21(848ms, 1705) sorted, meet
16 3Sum Closest Medium O(n^2) O(1) 56.32(145ms, 1705) sorted, meet
18 4Sum Medium O(n^3) O(1) 86.12(132ms, 1703) 3sum
19 Remove Nth Node From End of List Medium O(n) O(1) 93.74(42ms,170623)
26 Remove Duplicates from Sorted Array Easy O(n) O(1) 77.68(79ms,170801)
27 Remove Element Easy O(n) O(1) 67.84(45ms, 1703)
28 Implement strStr() Easy O(mn) O(n) 41.03(58ms, 1703)
30 Substring with Concatenation of All Words Hard O(mnk) O(nk) 70.72(98ms,170620) use find info
42 Trapping Rain Water Hard O(n) O(n) 72.91(52ms,170627) PEAK peak PEAK
61 Rotate List Medium O(n) O(1) 83.99(45ms,170811)

String

No. Title Difficulty Time Space Solution Runtime Tip
3 Longest Substring Without Repeating Characters Medium O(n) O(n) 88.87(89ms, 1704) between the same
5 Longest Palindromic Substring Medium O(n) O(n) 91.31(95ms, 170729) Manacher
6 ZigZag Conversion Medium O(n) O(1) 61.39(122ms, 1703) join
8 String to Integer (atoi) Medium O(n) O(1) 44.69(78ms, 1704)
10 Regular Expression Matching Hard O(mn) O(mn) 85.45(82ms, 1705)
12 Integer to Roman Medium O(n) O(1) 90.62(105ms, 1705) directly
13 Roman to Integer Medium O(n) O(1) 88.58(132ms, 1705) lambda
14 Longest Common Prefix Easy O(mn) O(1) 84.60(42ms, 1704) zip is better
17 Letter Combinations of a Phone Number Medium O(4^n) O(n) 62.18(42ms, 1705) reduce works
20 Valid Parentheses Easy O(n) O(n) 92.77(39ms, 1703)
22 Generate Parentheses Medium O(4^n / n^(3/2)) O(n) 28.90(65ms, 1703) generate, closed?
28 Implement strStr() Easy O(mn) O(n) 41.03(58ms, 1703)
30 Substring with Concatenation of All Words Hard O(mnk) O(nk) 70.72(98ms,170620) use find info
32 Longest Valid Parentheses Hard O(n) O(1) 72.88(79ms,170614)
38 Count and Say Hard O(n) O(1) 41.89(55ms, 1705) pythonchallenge (level 10)
43 Multiply Strings Medium O(m*n) O(m+n) 94.76(49ms,1704) / 76.65(168ms,170629) carry, once
44 Wildcard Matching Hard O(m*n) O(1) 86.49(109ms,1704)
49 Group Anagrams Medium O(mn) O(mn) 90.95(212ms, 170711) frequency with hash
58 Length of Last Word Easy O(1) O(1) 84.46(32ms,170729)
65 Valid Number Hard O(1) O(1) 37.72(62ms,170729)
67 Add Binary Easy O(1) O(1) 82.49(42ms,1705)
68 Text Justification Hard O(n) O(n) 59.32(35ms,1705)
71 Simplify Path Medium O(n) O(n) 67.63(42ms,170827)
72 Edit Distance Hard O(mn) O(n) 91.79(198ms,17005)

Binary Search

No. Title Difficulty Time Space Solution Runtime Tip
4 Median of Two Sorted Arrays Hard O(log(m+n)) O(1) 78.16(99ms, 1706) find kth
29 Divide Two Integers Medium O(m/n) O(1) 33.58(68ms, 1703)
33 Search in Rotated Sorted Array Medium O(logn) O(1) 21.87(58ms, 1703) Binary Search
34 Search for a Range Medium O(logn) O(1) 73.72(45ms,170620) Search left, then right
35 Search Insert Position Easy O(logn) O(1) 82.93(39ms,170620) check range & bisect
50 Pow(x, n) Medium O(m*n) O(m+n) 74.33(39ms, 1705)
69 Sqrt(x) Easy O(1) O(1) 77.55(42ms,1705) sqrtx

Divide & Conquer

No. Title Difficulty Time Space Solution Runtime Tip
4 Median of Two Sorted Arrays Hard O(log(m+n)) O(1) 78.16(99ms, 1706) find kth
23 Merge k Sorted Lists Hard O(nlogk) O(1) 98.15(105ms, 1703)
53 Maximum Subarray Medium O(n) O(1) 88.17(45ms,170719)

Backtracking

No. Title Difficulty Time Space Solution Runtime Tip
10 Regular Expression Matching Hard O(mn) O(mn) 85.45(82ms, 1705)
17 Letter Combinations of a Phone Number Medium O(4^n) O(n) 62.18(42ms, 1705) reduce works
22 Generate Parentheses Medium O(4^n / n^(3/2)) O(n) 28.90(65ms, 1703) generate, closed?
37 Sudoku Solver Hard O((9!)^9) O(1) 90.91(72ms,170623) check then put, if wrong backtracking. Or play like human
39 Combination Sum Medium O(k*n^k) O(k^2) 99.81(72ms,170625) backtracking, check target
40 Combination Sum II Medium O(k*n^k) O(k^2) 93.17(65ms,170626)
44 Wildcard Matching Hard O(m*n) O(1) 86.49(109ms,1704)
46 Permutations Medium O(n!) O(n*n!) 87.53(66ms,1704)
47 Permutations II Medium O(n!) O(n*n!) 94.36(99ms,1703)
51 N-Queens Hard O(n^3) O(n*n) 100(62ms,170717) bit
52 N-Queens II Hard O(n^3) O(n*n) 99.27(42ms, 1704) bit
60 Permutation Sequence Medium O(n) O(n) 33.52(45ms, 1705)

Dynamic Programming

No. Title Difficulty Time Space Solution Runtime Tip
10 Regular Expression Matching Hard O(mn) O(mn) 85.45(82ms, 1705)
32 Longest Valid Parentheses Hard O(n) O(1) 72.88(79ms,170614)
44 Wildcard Matching Hard O(m*n) O(1) 86.49(109ms,1704)
53 Maximum Subarray Medium O(n) O(1) 88.17(45ms,170719)
62 Unique Paths Medium O(1) O(1) 76.22(32ms,1705) directly
63 Unique Paths II Medium O(mn) O(m) 51,91(39ms,170815)
64 Minimum Path Sum Medium O(mn) O(m) 66.04(58ms,1705)
70 Climbing Stairs Easy O(1) O(1) 38.2(36ms,1705)
72 Edit Distance Hard O(mn) O(n) 91.79(198ms,17005)

Stack

No. Title Difficulty Time Space Solution Runtime Tip
20 Valid Parentheses Easy O(n) O(n) 92.77(39ms, 1703)
42 Trapping Rain Water Hard O(n) O(n) 72.91(52ms,170627) PEAK peak PEAK
71 Simplify Path Medium O(n) O(n) 67.63(42ms,170827)

Heap

No. Title Difficulty Time Space Solution Runtime Tip
23 Merge k Sorted Lists Hard O(nlogk) O(1) 98.15(105ms, 1703) replace

Greedy

No. Title Difficulty Time Space Solution Runtime Tip
44 Wildcard Matching Hard O(m*n) O(1) 86.49(109ms,1704)
45 Jump Game II Hard O(n) O(n) 98.24(49ms,170705)
55 Jump Game Medium O(m) O(1) 63.92(52ms,170723)

Sort

No. Title Difficulty Time Space Solution Runtime Tip
56 Merge Intervals Medium O(m) O(1) 92.09(72ms,170726)
57 Insert Interval Hard O(m) O(1) 98.84(62ms,170727) leetcode may give wrong Runtime

About

The Python 3 journey of leetcode

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages