The C# solutions for LeetCode problems.
The C# solutions for LeetCode problems.
| # | Title | Solutions | Time | Space | Comments |
|---|---|---|---|---|---|
| 1 | Two Sum | C#(232ms) | O(N) | O(N) | |
| 2 | Add Two Numbers | C#(112ms) | O(Max(N, M)) | O(1) | |
| 3 | Longest Substring Without Repeating Characters | C#(80ms) | O(N) | O(1) | C# use array will slower |
| 4 | Median of Two Sorted Arrays | C#(112ms) | O(Log(N+M)) | O(1) | |
| 5 | Longest Palindromic Substring | C#(80ms) | O(N) | O(N) | Use Manacher's Algorithm |
| 6 | ZigZag Conversion | C#(148ms) | O(N) | O(N) | |
| 7 | Reverse Integer | C#(40ms) | O(1) | O(1) | |
| 8 | String to Integer (atoi) | C#(144ms) | O(1) | O(1) | |
| 9 | Palindrome Number | C#(64ms) | O(1) | O(1) | |
| 10 | Regular Expression Matching | C#(68ms) | O(N*M) | O(N*M) | |
| 11 | Container With Most Water | C#(104ms) | O(N) | O(1) | |
| 12 | Integer to Roman | C#(96ms) | O(N) | O(1) | |
| 13 | Roman to Integer | C#(84ms) | O(N) | O(1) | |
| 14 | Longest Common Prefix | C#(96ms) | O(N) | O(1) | |
| 15 | 3Sum | C#(300ms) | O(N2) | O(M) | For Python solution, use count to reduce time to O(min(N, M2)) and space to O(M) |
| 16 | 3Sum Closest | C#(164ms) | O(N2) | O(1) | |
| 17 | Letter Combinations of a Phone Number | C#(232ms) | O(4N) | O(4N) | |
| 18 | 4Sum | C#(532ms) | O(N2) | O(N2) | |
| 19 | Remove Nth Node From End of List | C#(152ms) | O(N) | O(1) | |
| 20 | Valid Parentheses | C#(68ms) | O(N) | O(N) | |
| 21 | Merge Two Sorted Lists | C#(88ms) | O(N1+N2) | O(1) | |
| 22 | Generate Parentheses | C#(232ms) | O(N) | O(?) | |
| 23 | Merge k Sorted Lists | C#(104ms) | O(N*logk) | O(1) | Python solution use heap to compare the lists, so reduce time to O(N logK) but increase space to O(k) |
| 24 | Swap Nodes in Pairs | C#(148ms) | O(N) | O(1) | |
| 25 | Reverse Nodes in k-Group | C#(160ms) | O(N) | O(1) | |
| 26 | Remove Duplicates from Sorted Array | C#(248ms) | O(N) | O(1) | |
| 27 | Remove Element | C#(236ms) | O(N) | O(1) | |
| 28 | Implement strStr() | C#(80ms) | O(N+M) | O(1) | Use Knuth–Morris–Pratt Algorithm |
| 29 | Divide Two Integers | C#(60ms) | O(N) | O(1) | |
| 30 | Substring with Concatenation of All Words | C#(828ms) | O(N*M) | O(M) | |
| 31 | Next Permutation | C#(232ms) | O(N) | O(1) | |
| 32 | Longest Valid Parentheses | C#(124ms) | O(N) | O(1) | |
| 33 | Search in Rotated Sorted Array | C#(84ms) | O(N) | O(1) | |
| 34 | Search for a Range | C#(240ms) | O(LogN) | O(1) | |
| 35 | Search Insert Position | C#(92ms) | O(LogN) | O(1) | |
| 36 | Valid Sudoku | C#(160ms) | O(1) | O(1) | |
| 37 | Sudoku Solver | C#(168ms) | O(1) | N(1) | |
| 38 | Count and Say | C#(80ms) | O(N2) | O(N) | Python use an dictionary of answers |
| 39 | Combination Sum | C#(236ms) | O(N!) | O(N) | |
| 40 | Combination Sum II | C#(484ms) | O(N!) | O(N) | |
| 41 | First Missing Positive | C#(84ms) | O(N) | O(1) | |
| 42 | Trapping Rain Water | C#(88ms) | O(N) | O(1) | |
| 43 | Multiply Strings | C#(140ms) | O(N*M) | O(N+M) | |
| 44 | Wildcard Matching | C#(160ms) | O(N*M) | O(1) | Similar with Problem No. 10 |
| 45 | Jump Game II | C#(88ms) | O(N) | O(1) | Use Greedy Algorithm |
| 46 | Permutations | C#(492ms) | O(N!) | (N) | Get inspired by Heap's Algorithm |
| 47 | Permutations II | C#(492ms) | O(N!) | (N) | Get inspired by Heap's Algorithm |
| 48 | Rotate Image | C#(148ms) | O(N2) | O(1) | |
| 49 | Group Anagrams | C#(288ms) | O(N K log K) | O(N K) | Linear algorithm will slower and cost more memory |
| 50 | Pow(x, n) | C#(48ms) | O(LogN) | O(1) |
| # | Title | Solutions | Time | Space | Comments |
|---|---|---|---|---|---|
| 51 | N-Queens | C#(396ms) | O(N!) | O(N) | |
| 52 | N-Queens II | C#(52ms) | O(N!) | O(N) | |
| 53 | Maximum Subarray | C#(88ms) | O(N) | O(1) | |
| 54 | Spiral Matrix | C#(476ms) | O(N) | O(1) | |
| 55 | Jump Game | C#(96ms) | O(N) | O(1) | Use Greedy Algorithm |
| 56 | Merge Intervals | C#(256ms) | O(NLogN) | O(1) | |
| 57 | Insert Interval | C#(252ms) | O(N) | O(N) | |
| 58 | Length of Last Word | C#(72msms) | O(N) | O(1) | |
| 59 | Spiral Matrix II | C#(48ms) | O(N2) | O(N2) | |
| 60 | Permutation Sequence | C#(80ms) | O(N) | (N) | Use Cantor Expansion (Introduction to Algorithms, MIT) |
| 61 | Rotate List | C#(84ms) | O(N) | O(1) | |
| 62 | Unique Paths | C#(40ms) | O(Min(M, N)) | O(1) | Use dynamic programing will cost O(M*N) time and O(Min(M, N)) space |
| 63 | Unique Paths II | C#(160ms) | O(M*N) | O(Min(M, N)) | |
| 64 | Minimum Path Sum | C#(104ms) | O(M*N) | O(Min(M, N)) | Update grid to not use new space |
| 65 | Valid Number | C#(144ms) | O(N) | O(1) | |
| 66 | Plus One | C#(228ms) | O(N) | O(N) | |
| 67 | Add Binary | C#(80ms) | O(N) | O(N) | |
| 68 | Text Justification | C#(244ms) | O(N) | O(N) | |
| 69 | Sqrt(x) | C#(44ms) | O(LogN) | O(1) | Use Newton–Raphson Method to computing square root |
| 70 | Climbing Stairs | C#(40ms) | O(N) | O(1) | |
| 71 | Simplify Path | C#(132ms) | O(N) | O(N) | |
| 72 | Edit Distance | C#(76ms) | O(N*M) | O(Min(N,M)) | |
| 73 | Set Matrix Zeroes | C#(184ms) | O(N*M) | O(N+M) | When use constant space, solution will slower |
| 74 | Search a 2D Matrix | C#(92ms) | O(Log(N+M)) | O(1) | |
| 75 | Sort Colors | C#(236ms) | O(N) | O(1) | |
| 76 | Minimum Window Substring | C#(84ms) | O(N+M) | O(1) | |
| 77 | Combinations | C#(416ms) | O((N-K)!) | O(N!/K!) | |
| 78 | Subsets | C#(232ms) | O(N*2n) | O(1) | |
| 79 | Word Search | C#(148ms) | O(N*M) | O(N*M) | |
| 80 | Remove Duplicates from Sorted Array II | C#(480ms) | O(N) | O(1) | |
| 81 | Search in Rotated Sorted Array II | C#(156ms) | O(N) | O(1) | |
| 82 | Remove Duplicates from Sorted List II | C#(168ms) | O(N) | O(1) | |
| 83 | Remove Duplicates from Sorted List | C#(92ms) | O(N) | O(1) | |
| 84 | Largest Rectangle in Histogram | C#(96ms) | O(N) | O(N) | |
| 85 | Maximal Rectangle | C#(120ms) | O(N*M) | O(M) | |
| 86 | Partition List | C#(148ms) | O(N) | N(1) | |
| 87 | Scramble String | C#(104ms) | O(NLogN) | O(1) | |
| 88 | Merge Sorted Array | C#(236ms) | O(M+N) | O(1) | |
| 89 | Gray Code | C#(288ms) | O(2n) | O(2n) | |
| 90 | Subsets II | C#(296ms) | O(2n) | O(2n) | |
| 91 | Decode Ways | C#(76ms) |
No open issues yet, or sync has not completed.