The JavaScript solutions for LeetCode problems.
# | Title | Solutions | Time | Space | Comments |
---|---|---|---|---|---|
1 | Two Sum | JavaScript(72ms) | O(N) | O(N) | |
2 | Add Two Numbers | JavaScript(260ms) | O(Max(N, M)) | O(1) | |
3 | Longest Substring Without Repeating Characters | JavaScript(240ms) | O(N) | O(1) | C# use array will slower |
4 | Median of Two Sorted Arrays | JavaScript(128ms) | O(Log(N+M)) | O(1) | |
5 | Longest Palindromic Substring | JavaScript(128ms) | O(N) | O(N) | Use Manacher's Algorithm |
6 | ZigZag Conversion | JavaScript(188ms) | O(N) | O(N) | |
7 | Reverse Integer | JavaScript(129ms) | O(1) | O(1) | |
8 | String to Integer (atoi) | JavaScript(122ms) | O(1) | O(1) | |
9 | Palindrome Number | JavaScript(315ms) | O(1) | O(1) | |
10 | Regular Expression Matching | JavaScript(276ms) | O(N*M) | O(N*M) | |
11 | Container With Most Water | JavaScript(80ms) | O(N) | O(1) | |
15 | 3Sum | JavaScript(128ms) | O(N2) | O(M) | For Python solution, use count to reduce time to O(min(N, M2)) and space to O(M) |
31 | Next Permutation | JavaScript(76ms) | O(N) | O(1) | |
33 | Search in Rotated Sorted Array | JavaScript(68ms) | O(N) | O(1) | |
42 | Trapping Rain Water | JavaScript(80ms) | O(N) | O(1) |
# | Title | Solutions | Time | Space | Comments |
---|---|---|---|---|---|
53 | Maximum Subarray | JavaScript(72ms) | O(N) | O(1) | |
56 | Merge Intervals | JavaScript(88ms) | O(NLogN) | O(1) | |
84 | Largest Rectangle in Histogram | JavaScript(84ms) | O(N) | O(N) | |
85 | Maximal Rectangle | JavaScript(88ms) | O(N*M) | O(M) |
# | Title | Solutions | Time | Space | Comments |
---|---|---|---|---|---|
121 | Best Time to Buy and Sell Stock | JavaScript(80ms) | O(N) | O(1) | |
127 | Word Ladder | JavaScript(120ms) | O(N*M) | O(N*M) | Bidirectional BFS |
# | Title | Solutions | Time | Space | Comments |
---|---|---|---|---|---|
199 | Binary Tree Right Side View | JavaScript(76ms) | O(N) | O(h) | |
200 | Number of Islands | JavaScript(96ms) | O(N*M) | O(N*M) |
# | Title | Solutions | Time | Space | Comments |
---|---|---|---|---|---|
238 | Product of Array Except Self | JavaScript(92ms) | O(N) | O(1) |
# | Title | Solutions | Time | Space | Comments |
---|---|---|---|---|---|
301 | Remove Invalid Parentheses | JavaScript(80ms) | O(2N) | O(N) |
# | Title | Solutions | Time | Space | Comments |
---|---|---|---|---|---|
560 | Subarray Sum Equals K | JavaScript(120ms) | O(N) | O(1) |