Skip to content

rhedgpeth/LeetCode-CS

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AppVeyor Build Status Solved Problems

LeetCode

The C# solutions for LeetCode problems.

Problems

Table of Contents

Problems 001-050

Back to Table of Contents

# 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)

Problems 051-100

Back to Table of Contents

# 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) O(N) O(N)
92 Reverse Linked List II C#(104ms) O(N) O(1)
93 Restore IP Addresses C#(292ms) O(1) O(1)
94 Binary Tree Inorder Traversal C#(280ms) O(N) O(N)
95 Unique Binary Search Trees II C#(208ms) O(N) O(N)
96 Unique Binary Search Trees C#(36ms) O(N) O(1) Catalan number
97 Interleaving String C#(84ms) O(N*M) O(N*M) Dynamic Programing
98 Validate Binary Search Tree C#(96ms) O(N) O(1)
99 Recover Binary Search Tree C#(140ms) O(N) O(N) Morris Traversal
100 Same Tree C#(84ms) O(N) O(N)

Problems 101-150

Back to Table of Contents

# Title Solutions Time Space Comments
101 Symmetric Tree C#(96ms) O(N) O(N)
102 Binary Tree Level Order Traversal C#(240ms) O(N) O(N)
103 Binary Tree Zigzag Level Order Traversal C#(244ms) O(N) O(N)
104 Maximum Depth of Binary Tree C#(88ms) O(N) O(1)
105 Construct Binary Tree from Preorder and Inorder Traversal C#(100ms) O(N) O(N)
106 Construct Binary Tree from Inorder and Postorder Traversal C#(96ms) O(N) O(N)
107 Binary Tree Level Order Traversal II C#(236ms) O(N) O(N)
108 Convert Sorted Array to Binary Search Tree C#(88ms) O(N) O(N)
109 Convert Sorted List to Binary Search Tree C#(116ms) O(N) O(LogN)
110 Balanced Binary Tree C#(96ms) O(N) O(1)
111 Minimum Depth of Binary Tree C#(96ms) O(N) O(N)
112 Path Sum C#(96ms) O(N) O(N)
113 Path Sum II C#(292ms) O(N) O(N)
114 Flatten Binary Tree to Linked List C#(112ms) O(N) O(1)
115 Distinct Subsequences C#(88ms) O(MN) O(MN) Dynamic Programming
116 Populating Next Right Pointers in Each Node C#(164ms) O(N) O(N)
117 Populating Next Right Pointers in Each Node II C#(244ms) O(N) O(N)
118 Pascal's Triangle C#(200ms) O(N2) O(N2)
119 Pascal's Triangle II C#(196ms) O(N2) O(N)
120 Pascal's Triangle C#(112ms) O(N2) O(1)
121 Best Time to Buy and Sell Stock C#(92ms) O(N) O(1)
122 Best Time to Buy and Sell Stock II C#(92ms) O(N) O(1)
123 Best Time to Buy and Sell Stock III C#(92ms) O(N) O(1)
124 Binary Tree Maximum Path Sum C#(104ms) O(N) O(N)
125 Valid Palindrome C#(76ms) O(N) O(1)
126 Word Ladder II C#(332ms) O(N*M) O(N*M) Bidirectional BFS
127 Word Ladder C#(136ms) O(N*M) O(N*M) Bidirectional BFS
128 Longest Consecutive Sequence C#(96ms) O(N) O(N)
129 Sum Root to Leaf Numbers C#(88ms) O(N) O(N)
130 Surrounded Regions C#(332ms) O(N) O(N) Union Find
131 Palindrome Partitioning C#(260ms)
133 Clone Graph C#(248ms) O(N) O(N)
134 Gas Station C#(88ms) O(N) O(1)
136 Single Number C#(96ms) O(N) O(1)
137 Single Number II C#(96ms) O(N) O(1)
138 Copy List with Random Pointer C#(92ms) O(N) O(N)
139 Word Break C#(92ms) O(N2) O(N)
140 Word Break II C#(256ms) O(2N) O(2N)
141 Linked List Cycle C#(96ms) O(N) O(1)
143 Reorder List C#(108ms) O(N) O(1)
146 LRU Cache C#(244ms) O(1) O(N)
148 Sort List C#(108ms) O(NlogN) O(1)

Problems 151-200

Back to Table of Contents

# Title Solutions Time Space Comments
151 Reverse Words in a String C#(88ms) O(N) O(N)
152 Maximum Product Subarray C#(88ms) O(N) O(1)
153 Find Minimum in Rotated Sorted Array C#(88ms) O(LogN) O(1)
154 Find Minimum in Rotated Sorted Array II C#(84ms) O(logN) O(1)
155 Min Stack C#(132ms) O(1) O(N)
157 Read N Characters Given Read4 C#(80ms)
158 Read N Characters Given Read4 II - Call multiple times C#(264ms) O(N) O(1)
159 Longest Substring with At Most Two Distinct Characters C#(72ms) O(N) O(1)
160 Intersection of Two Linked Lists C#(116ms) O(N+M) O(1)
162 Find Peak Element C#(92ms) O(LogN) O(1)
165 Compare Version Numbers C#(72ms) O(N+M) O(N+M)
166 Fraction to Recurring Decimal C#(76ms) O(N) O(N)
167 Two Sum II - Input array is sorted C#(244ms) O(N) O(1)
168 Excel Sheet Column Title C#(68ms) O(logN) O(1)
169 Majority Element C#(104ms) O(N) O(1)
170 Two Sum III - Data structure design C#(216ms) O(N) O(N)
171 Excel Sheet Column Number C#(72ms) O(N) O(1)
172 Factorial Trailing Zeroes C#(40ms) O(logN) O(1)
173 Binary Search Tree Iterator C#(156ms) O(N) O(h)
174 Dungeon Game C#(92ms) O(N*M) O(N*M)
179 Largest Number C#(124ms) O(NlogN) O(N)
189 Rotate Array C#(232ms) O(N) O(1)
190 Reverse Bits C#(44ms) O(1) O(1)
191 Number of 1 Bits C#(36ms) O(1) O(1)
198 House Robber C#(88ms) O(N) O(1)
199 Binary Tree Right Side View C#(232ms) O(N) O(h)
200 Number of Islands C#(104ms) O(N*M) O(N*M)

Problems 201-250

Back to Table of Contents

# Title Solutions Time Space Comments
201 Bitwise AND of Numbers Range C#(48ms) O(logN) O(1) Brian Kernighan's Algorithm
202 Happy Number C#(40ms) O(N) O(N)
203 Remove Linked List Elements C#(92ms) O(N) O(1)
204 Count Primes C#(60ms) O(N) O(N)
205 Isomorphic Strings C#(72ms) O(N) O(1)
206 Reverse Linked List C#(88ms) O(N) O(1)
207 Course Schedule C#(116ms) O(N2 + E) O(N2)
208 Implement Trie (Prefix Tree) C#(184ms) O(N) O(N)
209 Minimum Size Subarray Sum C#(100ms) O(N) O(1)
210 Course Schedule II C#(272ms) O(N2 + E) O(N2)
211 Add and Search Word - Data structure design C#(272ms) O(1) O(N)
212 Word Search II C#(272ms) O(N*M) O(K)
213 House Robber II C#(84ms) O(N) O(1)
215 Kth Largest Element in an Array C#(100ms) O(NLogN) O(1)
216 Combination Sum III C#(200ms) O(9! * K / (9-K)!) O(K)
217 Contains Duplicate C#(112ms) O(N) O(N)
218 The Skyline Problem C#(288ms) O(NLogN) O(N)
219 Contains Duplicate II C#(100ms) O(N) O(N)
220 Contains Duplicate III C#(100ms) O(NlogN) O(N)
221 Maximal Square C#(112ms) O(N*M) O(N)
222 Count Complete Tree Nodes C#(112ms) O(log2N) O(1)
224 Basic Calculator C#(80ms) O(N) O(N)
225 Implement Stack using Queues C#(92ms) O(1) O(N)
226 Invert Binary Tree C#(92ms) O(N) O(1)
227 Basic Calculator II C#(76ms) O(N) O(N)
229 Majority Element II C#(240ms) O(N) O(1) Boyer-Moore Voting Algorithm
230 Kth Smallest Element in a BST C#(96ms) O(N) O(N)
231 Power of Two C#(36ms) O(1) O(1)
232 Implement Queue using Stacks C#(92ms)
234 Palindrome Linked List C#(100ms) O(N) O(1)
235 Lowest Common Ancestor of a Binary Search Tree C#(108ms) O(h) O(1)
236 Lowest Common Ancestor of a Binary Tree C#(100 ms) O(N) O(N)
237 Delete Node in a Linked List C#(96ms) O(1) O(1)
238 Product of Array Except Self C#(260ms) O(N) O(1)
239 Sliding Window Maximum C#(252ms) O(N) O(N)
240 Search a 2D Matrix II C#(244ms) O(LogN) O(1)
242 Valid Anagram C#(68ms) O(N) O(1)
243 Shortest Word Distance C#(92ms) O(N) O(1)
246 Strobogrammatic Number C#(68ms) O(N) O(1)

Problems 251-300

Back to Table of Contents

# Title Solutions Time Space Comments
252 Meeting Rooms C#(100ms) O(NlogN) O(1)
253 Meeting Rooms II C#(104ms) O(NlogN) O(N)
256 Paint House C#(88ms) O(N) O(1)
257 Binary Tree Paths C#(248ms) O(N) O(N)
258 Add Digits C#(36ms) O(N) O(1)
260 Single Number III C#(228ms) O(N) O(1)
263 Ugly Number C#(40ms) O(1) O(1)
264 Ugly Number II C#(44ms) O(N) O(N)
266 Palindrome Permutation C#(68ms) O(N) O(1)
268 Missing Number C#(100ms) O(N) O(1)
269 Alien Dictionary C#(100ms) O(N2) O(N2)
270 Closest Binary Search Tree Value C#(96ms) O(logN) O(logN)
271 Encode and Decode Strings C#(284ms) O(N) O(N)
273 Integer to English Words C#(80ms) O(N) O(N)
274 H-Index C#(84ms) O(N) O(N)
275 H-Index II C#(112ms) O(logN) O(1)
276 Paint Fence C#(36ms) O(N*K) O(N*K)
278 First Bad Version C#(40ms) O(N) O(1)
279 Perfect Squares C#(84ms) O(N) O(N)
280 Wiggle Sort C#(260ms) O(N) O(1)
283 Move Zeroes C#(240ms) O(N) O(1)
285 Inorder Successor in BST C#(104ms) O(N) O(N)
287 Find the Duplicate Number C#(96ms) O(N) O(1)
289 Game of Life C# O(NM) O(1)
290 Word Pattern C#(68ms) O(N) O(N)
292 Nim Game C#(36ms) O(1) O(1)
293 Flip Game C#(220ms) O(N) O(N)
295 Find Median from Data Stream C#(308ms) O(LogN) O(N)
297 Serialize and Deserialize Binary Tree C#(120ms) O(N) O(N)
299 Bulls and Cows C#(84ms) O(N) O(1)
300 Longest Increasing Subsequence C#(84ms) O(NlogN) O(N)

Problems 301-350

Back to Table of Contents

# Title Solutions Time Space Comments
301 Remove Invalid Parentheses C#(240ms) O(2N) O(N)
303 Range Sum Query - Immutable C#(140ms) O(N) O(N)
305 Number of Islands II C#(1900ms) O(N*M+k2) O(K)
309 Best Time to Buy and Sell Stock with Cooldown C#(88ms) O(N) O(1)
311 Sparse Matrix Multiplication C#(260ms) O(N * M * P) O(N*P)
312 Burst Balloons C#(104ms) O(N3) O(N2)
314 Binary Tree Vertical Order Traversal C#(288ms) O(N) O(N)
315 Count of Smaller Numbers After Self C#(256ms) O(NlogN) O(N) BST
316 Remove Duplicate Letters C#(84ms) O(N) O(N)
317 Shortest Distance from All Buildings C#(140ms) O(N2M2) O(N*M)
322 Coin Change C#(108 ms) O(N*S) O(N)
326 Power of Three C#(76ms) O(1) O(1)
327 Count of Range Sum C#(108ms) O(NLogN) O(N)
328 Odd Even Linked List C#(92ms) O(N) O(1)
329 Longest Increasing Path in a Matrix C#(132ms) O(M*N) O(M*N)
332 Reconstruct Itinerary C#(292ms) O(NLogN) O(N)
336 Palindrome Pairs C#(620ms) O(N2K) O(N)
338 Counting Bits C#(220ms) O(N) O(1)
339 Nested List Weight Sum C#(60ms) O(N) O(N)
340 Longest Substring with At Most K Distinct Characters C#(88ms) O(N) O(N)
341 Flatten Nested List Iterator C#(280ms) O(1) O(1)
342 Power of Four C#(32ms) O(1) O(1)
344 Reverse String C#(388ms) O(N) O(1)
345 Reverse Vowels of a String C#(88ms) O(N) O(1)
346 Moving Average from Data Stream C#(152ms) O(1) O(N)
347 Top K Frequent Elements C#(256ms) O(NLogN) O(k)
348 Design Tic-Tac-Toe C#(132ms) O(1) O(N)
349 Intersection of Two Arrays C#(240ms) O(N+M) O(1)
350 Intersection of Two Arrays II C#(232ms) O(N+M) O(min(N, M))

Problems 351-400

Back to Table of Contents

# Title Solutions Time Space Comments
352 Data Stream as Disjoint Intervals C#(332ms) O(logN) O(N)
355 Design Twitter C#(308ms) O(1) O(1)
359 Logger Rate Limiter C#(248ms) O(N) O(N)
362 Design Hit Counter C#(104ms) O(1) O(1)
364 Nested List Weight Sum II C#(68ms) O(N) O(N)
366 Find Leaves of Binary Tree C#(236ms) O(N) O(logN)
367 Valid Perfect Square C#(40ms) O(logN) O(1)
368 Largest Divisible Subset C#(252ms) O(N2) O(N2)
370 Range Addition C#(344ms) O(N+K) O(1)
371 Sum of Two Integers C#(36ms) O(1) O(1)
374 Guess Number Higher or Lower C#(40ms) O(logN) O(1)
375 Guess Number Higher or Lower II C#(40ms) O(N2) O(N2)
380 Insert Delete GetRandom O(1) C#(144ms) O(N) O(N)
381 Insert Delete GetRandom O(1) - Duplicates allowed C#(192ms) O(N) O(N)
383 Ransom Note C#(72ms) O(N) O(1)
387 First Unique Character in a String C#(80ms) O(N) O(1)
389 Find the Difference C#(84ms) O(N) O(1)
392 Is Subsequence C#(76ms) O(T) O(1)
393 UTF-8 Validation C# O(N) O(1)
394 Decode String C#(80ms) O(N) O(N)
399 Evaluate Division C#(240ms) O(N) O(N)

Problems 401-450

Back to Table of Contents

# Title Solutions Time Space Comments
401 Binary Watch C#(236ms) O(1) O(1)
402 Remove K Digits C#(84ms) O(N) O(N)
403 Frog Jump C#(108ms) O(N2) O(N2)
404 Sum of Left Leaves C#(88ms) O(N) O(N)
405 Convert a Number to Hexadecimal C#(76ms) O(log16 N) O(log16 N)
406 Queue Reconstruction by Height C#(268ms) O(N2) O(N)
408 Valid Word Abbreviation C#(72ms) O(N) O(1)
409 Longest Palindrome C#(72ms) O(N) O(1)
410 Split Array Largest Sum C#(92ms) O(N∗log(sum of array)) O(1) Binary Search
412 Fizz Buzz C#(216ms) O(N) O(N)
414 Third Maximum Number C#(92ms) O(NlogN) O(1)
415 Add Strings C#(84ms) O(N) O(N)
416 Partition Equal Subset Sum C#(80ms) O(2N) O(N)
419 Battleships in a Board C#(100ms) O(N) O(1)
420 Strong Password Checker C#(72ms) O(N) O(N)
421 Maximum XOR of Two Numbers in an Array C#(152ms) O(N) O(N)
422 Valid Word Square C#(96ms) O(N*M) O(1)
425 Word Squares C#(340ms) O(N * 26^L * L) O(N*L)
426 Convert Binary Search Tree to Sorted Doubly Linked List C#(96ms) O(N) O(logN)
427 Construct Quad Tree C#(100ms) O(N*N) O(logN)
428 Serialize and Deserialize N-ary Tree C#(408ms) O(N) O(N)
429 N-ary Tree Level Order Traversal C#(296ms) O(N) O(H)
430 Flatten a Multilevel Doubly Linked List C#(88ms) O(N) O(N)
432 All O`one Data Structure C#(180ms) O(1) O(N)
434 Number of Segments in a String C#(68ms) O(N) O(1)
435 Non-overlapping Intervals C#(96ms) O(NlogN) O(1)
436 Find Right Interval C#(364ms) O(NlogN) O(N)
437 Path Sum III C# O(N) O(N)
438 Find All Anagrams in a String C#(244ms) O(N) O(1)
441 Arranging Coins C#(40ms) O(1) O(1)
442 Find All Duplicates in an Array C#(368ms) O(N) O(1)
443 String Compression C#(264ms) O(N) O(1)
445 Add Two Numbers II C#(108ms) N(N) O(1)
447 Number of Boomerangs C#(244ms) O(N2) O(N)
448 Find All Numbers Disappeared in an Array C#(296ms) O(N) O(1)
449 Serialize and Deserialize BST C#(112ms) O(N) O(N)
450 Delete Node in a BST C#(100ms) O(logN) O(logN)

Problems 451-500

Back to Table of Contents

# Title Solutions Time Space Comments
451 Sort Characters By Frequency C#(108ms) O(N) O(N)
452 Minimum Number of Arrows to Burst Balloons C#(212ms) O(NlogN) O(N)
453 Minimum Moves to Equal Array Elements C#(128ms) O(N) O(1)
455 Assign Cookies C#(116ms) O(NlogN) O(1)
458 Poor Pigs C#(36ms) O(1) O(1)
459 Repeated Substring Pattern C#(84ms) O(N) O(N)
460 LFU Cache C#(268ms) O(1) O(1)
461 Hamming Distance C#(36ms) O(1) O(1)
463 Island Perimeter C#(176ms) O(N*M) O(1)
465 Optimal Account Balancing C#(104ms) O(2N) O(N)
468 Validate IP Address C#(84ms) O(N) O(1)
470 Implement Rand10() Using Rand7() C#(228ms) O(1) O(1)
472 Concatenated Words C#(576ms) O(N2) O(N)
475 Heaters C#(152ms) O(NlogN) O(N)
476 Number Complement C#(32ms) O(1) O(1)
480 Sliding Window Median C#(648ms) O(NlogN) O(K)
482 License Key Formatting C#(96ms) O(N) O(N)
484 Find Permutation C#(236ms) O(N) O(1)
485 Max Consecutive Ones C#(136ms) O(N) O(1)
489 Robot Room Cleaner C#(112ms) O(N) O(N)
490 The Maze C#(124ms) O(NM) O(NM)
492 Construct the Rectangle C#(200ms) O(sqrt(N)) O(1)
493 Reverse Pairs C#(248ms) O(NlogN) O(N)
495 Teemo Attacking C#(124ms) O(N) O(1)
496 Next Greater Element I C#(236ms) O(N) O(N)
497 Random Point in Non-overlapping Rectangles C#(324ms) O(N) O(N)
498 Diagonal Traverse C#(288ms) O(N*M) O(1)
500 Keyboard Row C#(236ms) O(N) O(1)

Problems 501-550

Back to Table of Contents

# Title Solutions Time Space Comments
501 Find Mode in Binary Search Tree C#(240ms) O(N) O(1)
503 Next Greater Element II C#(344ms) O(N) O(N)
504 Base 7 C#(76ms) O(1) O(1)
506 Relative Ranks C#(260ms) O(N) O(N)
507 Perfect Number C#(36ms) O(1) O(1)
509 Fibonacci Number C#(40ms) O(N) O(1)
510 Inorder Successor in BST II C#(112ms) O(logN) O(1)
513 Find Bottom Left Tree Value C#(112ms) O(N) O(N)
515 Find Largest Value in Each Tree Row C#(248ms) O(N) O(N)
518 Coin Change 2 C#(92ms) O(N) O(N)
520 Detect Capital C#(72ms) O(N) O(N)
521 Longest Uncommon Subsequence I C#(68ms) O(N) O(1) Stupid question...
523 Continuous Subarray Sum C#(120ms) O(N) O(min(N,k))
525 Word Abbreviation C#(216ms) O(N) O(N)
528 Random Pick with Weight C#(208ms) O(logN) O(N)
529 Minesweeper C#(380ms) O(N*M) O(N+M)
530 Minimum Absolute Difference in BST C#(100ms) O(N) O(logN)
532 K-diff Pairs in an Array C#(148ms) O(N) O(N)
535 Encode and Decode TinyURL C#(88ms) O(1) O(N)
537 Complex Number Multiplication C#(84ms) O(N) O(1)
538 Convert BST to Greater Tree C#(104ms) O(N) O(N)
540 Single Element in a Sorted Array C#(92ms) O(logN) O(1)
541 Reverse String II C#(84ms) O(N) O(1)
543 Diameter of Binary Tree C#(96ms) O(N) O(N)
544 Output Contest Matches C#(80ms) O(N) O(N)
545 Boundary of Binary Tree C#(240ms) O(N) O(N)
547 Friend Circles C#(112ms) O(N2) O(N)

Problems 551-600

Back to Table of Contents

# Title Solutions Time Space Comments
551 Student Attendance Record I C#(76ms) O(N) O(1)
552 Student Attendance Record II C#(100ms) O(N) O(N)
557 Reverse Words in a String III C#(92ms) O(N) O(N)
559 Maximum Depth of N-ary Tree C#(408ms) O(N) O(N)
560 Subarray Sum Equals K C#(104ms) O(N) O(1)
561 Array Partition I C#(156ms) O(NlogN) O(1)
563 Binary Tree Tilt C#(104ms) O(N) O(N)
566 Reshape the Matrix C#(260ms) O(M*N) O(M*N)
567 Permutation in String C#(92ms) O(N) O(1)
572 Subtree of Another Tree C#(104ms) O(N*M) O(N)
575 Distribute Candies C#(264ms) O(N) O(N)
581 Shortest Unsorted Continuous Subarray C#(116ms) O(N) O(1)
582 Kill Process C#(340ms) O(N) O(N)
588 Design In-Memory File System C#(300ms) O(logN) O(N)
589 N-ary Tree Preorder Traversal C#(292ms) O(N) O(N)
590 N-ary Tree Postorder Traversal C#(280ms) O(N) O(N)
594 Longest Harmonious Subsequence C#(148ms) O(N) O(N)
598 Range Addition II C#(100ms) O(N) O(1)
599 Minimum Index Sum of Two Lists C#(296ms) O(N+N) O(min(N, M))

Problems 601-650

Back to Table of Contents

# Title Solutions Time Space Comments
604 Design Compressed String Iterator C#(160ms) O(N) O(N)
605 Can Place Flowers C#(108ms) O(N) O(1)
606 Construct String from Binary Tree C#(120ms) O(N) O(N)
609 Find Duplicate File in System C#(312ms) O(N) O(N)
616 Add Bold Tag in String C#(112ms)
617 Merge Two Binary Trees C#(112ms) O(N) O(1)
621 Task Scheduler C#(180ms) O(N) O(1)
624 Maximum Distance in Arrays C#(116ms) O(N*M) O(1)
628 Maximum Product of Three Numbers C#(132ms) O(N) O(1)
633 Sum of Square Numbers C#(36ms) O(logN) O(1)
636 Exclusive Time of Functions C#(272ms) O(N) O(N)
637 Average of Levels in Binary Tree C#(244ms) O(N) O(N)
642 Design Search Autocomplete System C#(820ms) O(N*k), O(p+q+mlogm) O(N*k) use Trie
643 Maximum Average Subarray I C#(236ms) O(N) O(1)
645 Set Mismatch C#(252ms)
647 Palindromic Substrings C#(68ms) O(N) O(N)

Problems 651-700

Back to Table of Contents

# Title Solutions Time Space Comments
653 Two Sum IV - Input is a BST C#(112ms) O(N) O(N)
654 Maximum Binary Tree C#(116ms) O(N) O(1)
657 Robot Return to Origin C#(76ms) O(N) O(1)
661 Image Smoother C#(320ms) O(N) O(N)
662 Maximum Width of Binary Tree C#(88ms) O(N) O(N)
665 Non-decreasing Array C#(116ms) O(N) O(1)
668 Kth Smallest Number in Multiplication Table C#(52ms) O(MLog(NM)) O(1)
669 Trim a Binary Search Tree C#(100ms) O(N) O(1)
671 Second Minimum Node In a Binary Tree C#(88ms) O(N) O(N)
674 Longest Continuous Increasing Subsequence C#(88ms) O(N) O(1)
678 Valid Parenthesis String C#(68ms) O(N) O(1)
680 Valid Palindrome II C#(96ms) O(N) O(1)
681 Next Closest Time C#(92ms) O(1) O(1)
682 Baseball Game C#(92ms) O(N) O(N)
683 K Empty Slots C#(260ms) O(N) O(N)
686 Repeated String Match C#(76ms) O(N+M) O(1)
687 Longest Univalue Path C#(172ms) O(N) O(logN)
690 Employee Importance C#(72ms) O(N) O(N)
692 Top K Frequent Words C#(272ms) O(NlogK) O(N)
693 Binary Number with Alternating Bits C#(40ms) O(1) O(1)
695 Max Area of Island C#(104ms) O(N*M) O(N*M)
696 Count Binary Substrings C#(84ms) O(N) O(1)
697 Degree of an Array C#(132ms) O(N) O(N)
698 Partition to K Equal Sum Subsets C#(80ms) O(N*2N) O(2N)
700 Search in a Binary Search Tree C#(112ms) O(logN) O(logN)

Problems 701-750

Back to Table of Contents

# Title Solutions Time Space Comments
701 Insert into a Binary Search Tree C#(128ms) O(logN) O(1)
702 Search in a Sorted Array of Unknown Size C#(160ms) O(logN) O(1)
703 Kth Largest Element in a Stream C#(200ms) O(KlogK) O(K)
704 Binary Search C#(120ms) O(logN) O(1)
705 Design HashSet C#(228ms)
706 Design HashMap C#(260ms)
708 Insert into a Sorted Circular Linked List C#(92ms) O(N) O(1)
709 To Lower Case C#(76ms) O(N) O(1)
713 Subarray Product Less Than K C#(236ms) O(N) O(1)
715 Range Module C#(488ms) O(N) O(N)
716 Max Stack C#(188ms) O(1) O(N)
717 1-bit and 2-bit Characters C#(84ms) O(N) O(1)
720 Longest Word in Dictionary C#(112ms) O(N) O(N)
721 Accounts Merge C#(468ms) O(NlogN) O(N)
722 Remove Comments C#(232ms) O(N) O(N)
723 Candy Crush C#(260ms) O((R*C)2) O(1)
724 Find Pivot Index C#(100ms) O(N) O(1)
726 Number of Atoms C#(96ms) O(N2) O(N)
727 Minimum Window Subsequence C#(180ms) O(NM) O(NM)
728 Self Dividing Numbers C#(196ms)
733 Flood Fill C#(248ms) O(N) O(N)
734 Sentence Similarity C#(96ms) O(N+P) O(P)
735 Asteroid Collision C#(264ms) O(N) O(N)
739 Daily Temperatures C#(328ms) O(N) O(N)
742 Closest Leaf in a Binary Tree C#(124ms) O(N) O(N)
743 Network Delay Time C#(236ms) O(N2 + E) O(N + E) Dijkstra's Algorithm
744 Find Smallest Letter Greater Than Target C#(116ms) O(logN) O(1)
746 Min Cost Climbing Stairs C#(88ms) O(N) O(1)
747 Largest Number At Least Twice of Others C#(84ms) O(N) O(1)
748 Shortest Completing Word C#(104ms) O(N) O(length)
750 Number Of Corner Rectangles C#(340ms) O(N2*M) O(N*M)

Problems 751-800

Back to Table of Contents

# Title Solutions Time Space Comments
751 IP to CIDR C#(244ms) O(N) O(N)
753 Cracking the Safe C#(120ms) O(N*kN) O(N*kN)
758 Bold Words in String C#(108ms) O(N*M) O(N)
759 Employee Free Time C#(432ms) O(NlogN) O(N)
760 Find Anagram Mappings C#(236ms) O(N^2) O(N)
762 Prime Number of Set Bits in Binary Representation C#(48ms) O(N) O(1)
763 Partition Labels C#(224ms) O(N) O(1)
765 Couples Holding Hands C#(92ms) O(N) O(N)
766 Toeplitz Matrix C#(96ms) O(M*N) O(1)
767 Reorganize String C#(84ms) O(N) O(1)
771 Jewels and Stones C#(68ms) O(N+M) O(N)
772 Basic Calculator III C#(76ms) O(N) O(N)
773 Sliding Puzzle C#(112ms) O(NM(N*M)!) O(NM(N*M)!)
777 Swap Adjacent in LR String C#(72ms) O(N) O(1)
780 Reaching Points C#(40ms) O(log(max(tx, ty))) O(1)
783 Minimum Distance Between BST Nodes C#(84ms) O(N) O(logN)
784 Letter Case Permutation C#(252ms) O(2N + N) O(2N + N)
787 Cheapest Flights Within K Stops C#(124ms) O(E*K) O(V2+V*K)
788 Rotated Digits C#(36ms) O(logN) O(logN)
791 Custom Sort String C#(104ms) O(N*M) O(N)
794 Valid Tic-Tac-Toe State C#(88ms) O(1) O(1)
796 Rotate String C#(72ms) O(N) O(N) Use Knuth–Morris–Pratt Algorithm
797 All Paths From Source to Target C#(268ms) O(N2) O(N2)
800 Similar RGB Color C#(84ms) O(1) O(1)

Problems 801-850

Back to Table of Contents

# Title Solutions Time Space Comments
804 Unique Morse Code Words C#(92ms)
806 Number of Lines To Write String C#(228ms) O(N) O(1)
807 Max Increase to Keep City Skyline C#(96ms) O(N2) O(N)
809 Expressive Words C#(92ms) O(NK) O(N)
811 Subdomain Visit Count C#(256ms) O(N) O(N)
812 Largest Triangle Area C#(92ms) O(N3) O(1)
814 Binary Tree Pruning C#(88ms) O(N) O(logN)
818 Race Car C#(40ms) O(NlogN) O(T)
819 Most Common Word C#(112ms) O(N) O(N)
821 Shortest Distance to a Character C#(224ms) O(N) O(N)
824 Goat Latin C#(84ms) O(N) O(N)
829 Consecutive Numbers Sum C#(40ms) O(sqrt(N)) O(1)
830 Positions of Large Groups C#(236ms) O(N) O(1)
832 Flipping an Image C#(240ms) O(N) O(1)
833 Find And Replace in String C#(104ms) O(N) O(N)
835 Image Overlap C#(92ms) O(N4) O(1)
836 Rectangle Overlap C#(108ms) O(1) O(1)
837 New 21 Game C#(44ms) O(N+W) O(N+W)
840 Magic Squares In Grid C#(88ms) O(N*M) O(1)
841 Keys and Rooms C#(108ms) O(N+E) O(N)
843 Guess the Word C#(92ms) O(N2) O(N)
844 Backspace String Compare C#(64ms) O(M+N) O(1)
846 Hand of Straights C#(264ms) O(NlogN) O(N)
849 Maximize Distance to Closest Person C#(100ms)

Problems 851-900

Back to Table of Contents

# Title Solutions Time Space Comments
852 Peak Index in a Mountain Array C#(96ms) O(LogN) O(1)
856 Score of Parentheses C#(72ms) O(N) O(1)
857 Minimum Cost to Hire K Workers C#(156ms) O(NLogN) O(N)
859 Buddy Strings C#(72ms) O(N) O(1)
860 Lemonade Change C#(108ms) O(N) O(1)
861 Score After Flipping Matrix C#(92ms) O(N) O(1)
863 All Nodes Distance K in Binary Tree C#(240ms) O(N) O(N)
865 Smallest Subtree with all the Deepest Nodes C#(96ms) O(N) O(N)
867 Transpose Matrix C#(252ms) O(N*M) O(N*M)
868 Binary Gap C#(32ms) O(logN) O(1)
872 Leaf-Similar Trees C#(92ms) O(N) O(N)
874 Walking Robot Simulation C#(216ms) O(N+M) O(M)
876 Middle of the Linked List C#(84ms) O(N) O(1)
877 Stone Game C#(92ms) O(N) O(N)
883 Projection Area of 3D Shapes C#(92ms) O(N*M) O(1)
884 Uncommon Words from Two Sentences C#(232ms) O(N) O(N)
885 Spiral Matrix III C#(228ms) O(max(R, C)2) O(1)
886 Possible Bipartition C#(296ms) O(N+E) O(N+E)
888 Fair Candy Swap C#(308ms)
889 Construct Binary Tree from Preorder and Postorder Traversal C#(100ms) O(N2) O(N)
890 Find and Replace Pattern C#(240ms) O(N*M) O(N)
892 Surface Area of 3D Shapes C#(92ms) O(N2) O(N) Same as 883: Projection Area of 3D Shapes
894 All Possible Full Binary Trees C#(256ms) O(2N) O(2N)
895 Maximum Frequency Stack C#(372ms) O(1) O(N)
896 Monotonic Array C#(160ms) O(N) O(1)
897 Increasing Order Search Tree C#(84ms) O(N) O(H)

Problems 901-950

Back to Table of Contents

# Title Solutions Time Space Comments
901 Online Stock Span C#(448ms) O(N) O(N)
904 Fruit Into Baskets C#(212ms) O(N) O(1)
905 Sort Array By Parity C#(244ms) O(N) O(1)
908 Smallest Range I C#(108ms) O(N) O(1)
912 Sort an Array C#(268ms)
913 Cat and Mouse C#(116ms) O(N3) O(N2)
914 X of a Kind in a Deck of Cards C#(96ms) O(NlogN) O(N)
917 Reverse Only Letters C#(76ms) O(N) O(N)
918 Maximum Sum Circular Subarray C#(152ms) O(N) O(1)
921 Minimum Add to Make Parentheses Valid C#(72ms) O(N) O(1)
922 Sort Array By Parity II C#(272ms) O(N) O(1)
925 Long Pressed Name C#(72ms) O(N+M) O(1)
929 Unique Email Addresses C#(108ms) O(N) O(N)
931 Minimum Falling Path Sum C#(100ms) O(N*N) O(N*N)
933 Number of Recent Calls C#(276ms) O(1) O(N)
937 Reorder Data in Log Files C#(256ms) O(NLogN) O(N) Array.Sort is not stable. System.Linq is slow
938 Range Sum of BST C#(172ms) O(N) O(1)
939 Minimum Area Rectangle C#(352ms) O(N2) O(N)
941 Valid Mountain Array C#(116ms) O(N) O(1)
942 DI String Match C#(224ms) O(N) O(N)
944 Delete Columns to Make Sorted C#(96ms) O(N*M) O(1)
946 Validate Stack Sequences C#(92ms) O(N) O(N)
947 Most Stones Removed with Same Row or Column C#(140ms) O(NlogN) O(N)
949 Largest Time for Given Digits C#(104ms) O(1) O(1)
950 Reveal Cards In Increasing Order C#(240ms) O(NlogN) O(N)

Problems 951-1000

Back to Table of Contents

# Title Solutions Time Space Comments
951 Flip Equivalent Binary Trees C#(108ms) O(N) O(logN)
952 Largest Component Size by Common Factor C#(276ms) O(NlogN) O(N)
953 Verifying an Alien Dictionary C#(88ms) O(N) O(1)
957 Prison Cells After N Days C#(244ms) O(N*M) O(2M)
959 Regions Cut By Slashes C#(92ms) O(N2) O(N2)
961 N-Repeated Element in Size 2N Array C#(124ms) O(N) O(N)
965 Univalued Binary Tree C#(92ms) O(N) O(1)
967 Numbers With Same Consecutive Differences C#(208ms) O(N*22) O(22)
969 Pancake Sorting C#(244ms) O(N2) O(1)
970 Powerful Integers C#(200ms) O(log2 bound) O(log2 bound)
973 K Closest Points to Origin C#(424ms) O(N) O(K)
975 Odd Even Jump C#(204ms) O(NlogN) O(N)
976 Largest Perimeter Triangle C#(128ms) O(NlogN) O(1)
977 Squares of a Sorted Array C#(284ms) O(N) O(N)
979 Distribute Coins in Binary Tree C#(92ms) O(N) O(h)
980 Unique Paths III C#(92ms) O(3N) O(N)
981 Time Based Key-Value Store C#(920ms) O(LogN) O(N)
983 Minimum Cost For Tickets C#(84ms) O(N) O(N)
985 Sum of Even Numbers After Queries C#(372ms) O(N) O(1)
986 Interval List Intersections C#(268ms) O(N) O(1)
987 Vertical Order Traversal of a Binary Tree C#(240ms) O(Nlog(N/k)) O(N)
989 Add to Array-Form of Integer C#(284ms) O(N) O(1)
993 Cousins in Binary Tree C#(84ms) O(N) O(N)
994 Rotting Oranges C#(88ms) O(N) O(N)
997 Find the Town Judge C#(292ms) O(N) O(N)
998 Maximum Binary Tree II C#(92ms) O(H) O(1)
999 Available Captures for Rook C#(88ms) O(N+M) O(1)

Problems 1001-1050

Back to Table of Contents

# Title Solutions Time Space Comments
1002 Find Common Characters C#(232ms) O(N) O(1)
1005 Maximize Sum Of Array After K Negations C#(96ms) O(NlogN) O(1)
1007 Minimum Domino Rotations For Equal Row C#(264ms) O(N) O(1)
1008 Construct Binary Search Tree from Preorder Traversal C#(88ms) O(N) O(N)
1009 Complement of Base 10 Integer C#(32ms) O(1) O(1)
1010 Pairs of Songs With Total Durations Divisible by 60 C#(124ms) O(N) O(N)
1011 Capacity To Ship Packages Within D Days C#(148ms) O(LogN) O(1) Binary Search
1013 Partition Array Into Three Parts With Equal Sum C#(140ms) O(N) O(1)
1018 Binary Prefix Divisible By 5 C#(256ms) O(N) O(1)
1021 Remove Outermost Parentheses C#(80ms) O(N) O(N)
1022 Sum of Root To Leaf Binary Numbers C#(92ms) O(N) O(N)
1024 Video Stitching C#(88ms) O(NlogN) O(1)
1025 Divisor Game C#(40ms) O(N^2) O(N)
1026 Maximum Difference Between Node and Ancestor C#(116ms) O(N) O(logN)
1029 Two City Scheduling C#(88ms) O(NlogN) O(1)
1030 Matrix Cells in Distance Order C#(256ms) O(N*M) O(N*M)
1032 Stream of Characters C#(628ms) O(M) O(N)
1033 Moving Stones Until Consecutive C#(200ms) O(1) O(1)
1035 Uncrossed Lines C#(84ms) O(N+M) O(N+M)
1037 Valid Boomerang C#(88ms) O(1) O(1)
1038 Binary Search Tree to Greater Sum Tree C#(88ms) O(N) O(N)
1041 Robot Bounded In Circle C#(68ms) O(N) O(1)
1042 Flower Planting With No Adjacent C#(384ms) O(N) O(N)
1043 Partition Array for Maximum Sum C#(96ms) O(KN) O(N)
1044 Longest Duplicate Substring C#(376ms) O(NlogN) O(N)
1046 Last Stone Weight C#(88ms) O(N) O(1)
1047 Remove All Adjacent Duplicates In String C#(92ms) O(N) O(N)
1048 Longest String Chain C#(216ms) O(N*M) O(N)

Problems 1051-1100

Back to Table of Contents

# Title Solutions Time Space Comments
1051 Height Checker C#(88ms) O(NlogN) O(N)
1055 Shortest Way to Form String C#(76ms) O(N+M) O(1)
1056 Confusing Number C#(36ms) O(log10 N) O(1)
1057 Campus Bikes C#(452ms) O(N*M) O(N*M)
1061 Lexicographically Smallest Equivalent String C#(120ms) O(N) O(N)
1062 Longest Repeating Substring C#(80ms) O(NlogN) O(N)
1064 Fixed Point C#(92ms) O(logN) O(1)
1065 Index Pairs of a String C#(240ms) O(N2) O(N)
1066 Campus Bikes II C#(96ms) O(N*M) O(N*M)
1071 Greatest Common Divisor of Strings C#(84ms) O(N2) O(N)
1072 Flip Columns For Maximum Number of Equal Rows C#(740ms) O(N*M) O(N*M)
1078 Occurrences After Bigram C#(232ms) O(N) O(N)
1079 Letter Tile Possibilities C#(68ms) O(N2) O(N2)
1081 Smallest Subsequence of Distinct Characters C#(84ms) O(N) O(N)
1085 Sum of Digits in the Minimum Number C#(72ms)
1086 High Five C#(236ms) O(NlogN) O(N)
1087 Brace Expansion C#(284ms) O(N2) O(N)
1089 Duplicate Zeros C#(248ms) O(N) O(1)
1094 Car Pooling C#(100ms) O(1) O(1)
1096 Brace Expansion II C#(308ms) O(N) ?
1099 Two Sum Less Than K C#(88ms) O(NlogN) O(1)
1100 Find K-Length Substrings With No Repeated Characters C#(80ms) O(N) O(K)

Problems 1101-1150

Back to Table of Contents

# Title Solutions Time Space Comments
1101 The Earliest Moment When Everyone Become Friends C#(144ms) O(NlogN) O(N)
1102 Path With Maximum Minimum Value C#(344ms) O(NM log NM ) O(N*M)
1103 Distribute Candies to People C#(196ms) O(N) O(N)
1104 Path In Zigzag Labelled Binary Tree C#(200ms) O(logN) O(1)
1108 Defanging an IP Address C#(80ms) O(N) O(N)
1110 Delete Nodes And Return Forest C#(252ms)
1111 Maximum Nesting Depth of Two Valid Parentheses Strings C#(232ms) O(N) O(1)
1114 Print in Order C#(112ms)
1118 Number of Days in a Month C#(36ms) O(1) O(1)
1119 Remove Vowels from a String C#(80ms) O(N) O(N)
1120 Maximum Average Subtree C#(104ms) O(N) O(N)
1122 Relative Sort Array C#(236ms) O(N) O(N)
1123 Lowest Common Ancestor of Deepest Leaves C#(104ms) O(N) O(logN)
1128 Number of Equivalent Domino Pairs C#(148ms) O(N) O(N)
1130 Minimum Cost Tree From Leaf Values C#(108ms) O(N) O(N)
1133 Largest Unique Number C#(92ms) O(N) O(1)
1134 Armstrong Number C#(36ms) O(N) O(1)
1137 N-th Tribonacci Number C#(36ms) O(N) O(1)
1140 Stone Game II C#(92ms)
1143 Longest Common Subsequence C#(68ms) O(M*N) O(Min(M, N))
1150 Check If a Number Is Majority Element in a Sorted Array C#(84ms) O(N) O(1)

Problems 1151-1200

Back to Table of Contents

# Title Solutions Time Space Comments
1152 Analyze User Website Visit Pattern C#(304ms) O(N2) O(N)
1154 Day of the Year C#(80ms) O(1) O(1)
1160 Find Words That Can Be Formed by Characters C#(108ms) O(N) O(1)
1161 Maximum Level Sum of a Binary Tree C#(212ms) O(N) O(logN)
1165 Single-Row Keyboard C#(76ms) O(N) O(1)
1167 Minimum Cost to Connect Sticks C#(372ms) O(N) O(N)
1170 Compare Strings by Frequency of the Smallest Character C#(244ms) O(N) O(1)
1175 Prime Arrangements C#(36ms) O(N) O(1)
1176 Diet Plan Performance C#(116ms) O(N) O(1)
1180 Count Substrings with Only One Distinct Letter C#(72ms) O(N) O(1)
1184 Distance Between Bus Stops C#(92ms) O(N) O(1)
1185 Day of the Week C#(80ms) O(1) O(1)
1189 Maximum Number of Balloons C#(68ms) O(N) O(1)
1190 Reverse Substrings Between Each Pair of Parentheses C#(88ms) O(N) O(N)
1192 Critical Connections in a Network C#(992ms) O(E) O(E)
1196 How Many Apples Can You Put into the Basket C#(88ms) O(NlogN) O(1)
1197 Minimum Knight Moves C#(44ms) O(N2) O(N2)
1198 Find Smallest Common Element in All Rows C#(168ms) O(N*M) O(N)
1200 Minimum Absolute Difference C#(328ms) O(N) O(N)

Problems 1201-1250

Back to Table of Contents

# Title Solutions Time Space Comments
1207 Unique Number of Occurrences C#(84ms) O(N) O(N)
1213 Intersection of Three Sorted Arrays C#(236ms) O(N) O(1)
1214 Two Sum BSTs C#(116ms) O(N+M) O(N+M)
1217 Play with Chips C#(84ms) O(N) O(1)
1219 Path with Maximum Gold C#(112ms) O(N*M) O(N*M)
1221 Split a String in Balanced Strings C#(68ms) O(N) O(1)
1222 Queens That Can Attack the King C#(288ms) O(1) O(1)
1227 Airplane Seat Assignment Probability C#(44ms) O(1) O(1)
1228 Missing Number In Arithmetic Progression C#(88ms) O(logN) O(1)
1229 Meeting Scheduler C#(416ms) O(N) O(1)
1232 Check If It Is a Straight Line C#(92ms) O(N) O(1)
1235 Maximum Profit in Job Scheduling C#(576ms) O(NlogN) O(N)
1236 Web Crawler C#(332ms) O(NE) O(N)
1237 Find Positive Integer Solution for a Given Equation C#(196ms) O(logM * logN)) O(A)
1238 Circular Permutation in Binary Representation C#(288ms) O(N2) O(N)
1242 Web Crawler Multithreaded C#(368ms) O(NE) O(N)
1243 Array Transformation C#(220ms) O(N) O(1)
1245 Tree Diameter C#(196ms) O(N) O(N)
1247 Minimum Swaps to Make Strings Equal C#(76ms) O(N) O(1)
1249 Minimum Remove to Make Valid Parentheses C#(96ms) O(N) O(N)

Problems 1251-1300

Back to Table of Contents

# Title Solutions Time Space Comments
1252 Cells with Odd Values in a Matrix C#(84ms) O(N*M) O(N+M)
1254 Number of Closed Islands C#(104ms) O(N*M) O(N*M)
1256 Encode Number C#(96ms) O(1) O(1)
1258 Synonymous Sentences C#(284ms) O(N2) O(N2)
1260 Shift 2D Grid C#(272ms) O(N*M) O(N*M)
1261 Find Elements in a Contaminated Binary Tree C#(156ms) O(1) O(N)
1265 Print Immutable Linked List in Reverse C# O(N) O(1)
1266 Minimum Time Visiting All Points C#(80ms) O(N) O(1)
1268 Search Suggestions System C#(360ms) O(N*M) O(N*M)
1271 Hexspeak C#(84ms) O(logN) O(1)
1273 Delete Tree Nodes C#(152ms) O(N) O(N)
1275 Find Winner on a Tic Tac Toe Game C#(100ms) O(N) O(1)
1277 Count Square Submatrices with All Ones C#(164ms) O(N*M) O(N*M)
1279 Traffic Light Controlled Intersection C#(248ms)
1281 Subtract the Product and Sum of Digits of an Integer C#(32ms) O(N) O(1)
1282 Group the People Given the Group Size They Belong To C#(252ms) O(N) O(N)
1286 Iterator for Combination C#(120ms) O(K) O(K)
1287 Element Appearing More Than 25% In Sorted Array C#(96ms) O(N) O(1)
1288 Remove Covered Intervals C#(100ms) O(NlogN) O(N)
1290 Convert Binary Number in a Linked List to Integer C#(84ms) O(N) O(1)
1291 Sequential Digits C#(204ms) O(1) O(1)
1295 Find Numbers with Even Number of Digits C#(92ms) O(N) O(N)
1296 Divide Array in Sets of K Consecutive Numbers C#(592ms) O(NlogN) O(N)
1299 Replace Elements with Greatest Element on Right Side C#(264ms) O(N) O(1)

Problems 1301-1350

Back to Table of Contents

# Title Solutions Time Space Comments
1302 Deepest Leaves Sum C#(116ms) O(N) O(N)
1304 Find N Unique Integers Sum up to Zero C#(200ms) O(logN) O(N)
1305 All Elements in Two Binary Search Trees C#(360ms) O(N+M) O(N+M)
1306 Jump Game III C#(116ms) O(N) O(N)
1309 Decrypt String from Alphabet to Integer Mapping C#(76ms) O(N) O(N)
1310 XOR Queries of a Subarray C#(464ms) O(N) O(1)
1313 Decompress Run-Length Encoded List C#(236ms) O(N) O(N)
1314 Matrix Block Sum C#(256ms) O(N*M) O(N*M)
1315 Sum of Nodes with Even-Valued Grandparent C#(112ms) O(N) O(1)
1317 Convert Integer to the Sum of Two No-Zero Integers C#(196ms) O(N) O(1)
1318 Minimum Flips to Make a OR b Equal to c C#(40ms) O(log(MAX(a,b,c))) O(1)
1323 Maximum 69 Numberr C#(40ms) O(1) O(1)
1325 Delete Leaves With a Given Value C#(100ms) O(N) O(logN)
1326 Minimum Number of Taps to Open to Water a Garden C#(104ms) O(NlogN) O(N)
1329 Sort the Matrix Diagonally C# O(N*N log Min(N, M)) O(N*M)
1331 Rank Transform of an Array C#(368ms) O(NlogN) O(N)
1332 Remove Palindromic Subsequences C#(68ms) O(N) O(1)
1337 The K Weakest Rows in a Matrix C#(248ms) O(M*N) O(K)
1338 Reduce Array Size to The Half C#(332ms) O(NloN) O(N)
1342 Number of Steps to Reduce a Number to Zero C#(40ms) O(logN) O(1)
1343 Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold C#(252ms) O(N) O(1)
1344 Angle Between Hands of a Clock C#(48ms) O(1) O(1)
1346 Check If N and Its Double Exist C#(92ms) O(N) O(N)
1347 Minimum Number of Steps to Make Two Strings Anagram C#(92ms) O(N) O(N)

Problems 1351-1400

Back to Table of Contents

# Title Solutions Time Space Comments
1351 Count Negative Numbers in a Sorted Matrix C#(100ms) O(N+M) O(1)
1353 Maximum Number of Events That Can Be Attended C#(436ms) O(NlogN) O(N)
1356 Sort Integers by The Number of 1 Bits C#(248ms) O(NlogN) O(1) Brian Kernighan's Algorithm
1357 Apply Discount Every n Orders C#(724ms) O(N) O(N)
1360 Number of Days Between Two Dates C#(68ms) O(1) O(1)
1365 How Many Numbers Are Smaller Than the Current Number C#(236ms) O(N) O(N) Count Sort
1370 Increasing Decreasing String C#(88ms) O(N) O(1)
1374 Generate a String With Characters That Have Odd Counts C#(72ms) O(N) O(N)
1375 Bulb Switcher III C#(164ms) O(N) O(1)
1379 Find a Corresponding Node of a Binary Tree in a Clone of That Tree C#(332ms) O(N) O(1)
1380 Lucky Numbers in a Matrix C#(260ms) O(N*M) O(N+M)
1381 Design a Stack With Increment Operation C#(152ms) O(1) O(N)
1382 Balance a Binary Search Tree C#(152ms) O(N) O(N)
1385 Find the Distance Value Between Two Arrays C#(96ms) O(NlogN) O(1)
1387 Sort Integers by The Power Value C#(100ms) O(N) O(N)
1389 Create Target Array in the Given Order C#(228ms) O(N^2) O(N)
1394 Find Lucky Integer in an Array C#(96ms) O(N) O(N)
1395 Count Number of Teams C#(92ms) O(N2) O(1)
1396 Design Underground System C#(624ms) O(1) O(N)
1399 Count Largest Group C#(48ms) O(N) O(N)
1400 Construct K Palindrome Strings C#(84ms) O(N) O(N)

Problems 1401-1450

Back to Table of Contents

# Title Solutions Time Space Comments
1403 Minimum Subsequence in Non-Increasing Order C#(244ms) O(N) O(1)
1408 String Matching in an Array C#(244ms) O(N2) O(N)
1409 Queries on a Permutation With Key C#(244ms) O(N*M) O(M)
1413 Minimum Value to Get Positive Step by Step Sum C#(88ms) O(N) O(1)
1414 Find the Minimum Number of Fibonacci Numbers Whose Sum Is K C#(44ms) O(N) O(N)
1415 The k-th Lexicographical String of All Happy Strings of Length n C#(92ms) O(3<sup?N) O(3<sup?N)
1417 Reformat The String C#(84ms) O(N) O(N)
1418 Display Table of Food Orders in a Restaurant C#(700ms) O(N) O(N)
1422 Maximum Score After Splitting a String C#(64ms) O(N) O(N)
1426 Counting Elements C#(100ms) O(NlogN) O(N)
1427 Perform String Shifts C#(96ms) O(N) O(1)
1428 Leftmost Column with at Least a One C#(96ms) O(N+M) O(1)
1429 First Unique Number C#(696ms) O(1) O(N)
1430 Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary Tree C#(132ms) O(logN) O(1)
1431 Kids With the Greatest Number of Candies C#(400ms) O(N) O(N)
1433 Check If a String Can Break Another String C#(112ms) O(N) O(1)
1436 Destination City C#(108ms) O(N) O(N)
1437 Check If All 1's Are at Least Length K Places Away C#(168ms) O(N) O(1)
1441 Build an Array With Stack Operations C#(384ms) O(N) O(N)
1442 Count Triplets That Can Form Two Arrays of Equal XOR C#(120ms) O(N) O(N)
1446 Consecutive Characters C#(72ms) O(N) O(1)
1447 Simplified Fractions C#(368ms) O(N2logN) O(1)
1448 Count Good Nodes in Binary Tree C#(180ms) O(N) )(logN)
1450 Number of Students Doing Homework at a Given Time C#(92ms) O(N) O(1)

Problems 1451-1500

Back to Table of Contents

# Title Solutions Time Space Comments
1455 Check If a Word Occurs As a Prefix of Any Word in a Sentence C#(64ms) O(N+M) O(M)
1457 Pseudo-Palindromic Paths in a Binary Tree C#(196ms) O(N) O(logN)
1460 Make Two Arrays Equal by Reversing Sub-arrays C#(100ms) O(N) O(N)
1464 Maximum Product of Two Elements in an Array C#(92ms) O(N) O(1)
1466 Reorder Routes to Make All Paths Lead to the City Zero C#(368ms) O(N) O(N)
1469 Find All The Lonely Nodes C#(252ms) O(N) O(N)
1470 Shuffle the Array C#(240ms) O(N) O(1)
1472 Design Browser History C#(320ms) O(1) O(N)
1474 Delete N Nodes After M Nodes of a Linked List C#(108ms) O(N) O(1)
1476 Subrectangle Queries C#(180ms) O(1) O(N)
1480 Running Sum of 1d Array C#(240ms) O(N) O(1)
1485 Clone Binary Tree With Random Pointer C#(252ms) O(N) O(N)
1486 XOR Operation in an Array C#(36ms) O(N) O(1)
1490 Clone N-ary Tree C#(420ms) O(N) O(N)
1491 Average Salary Excluding the Minimum and Maximum Salary C#(88ms) O(N) O(1)
1492 The kth Factor of n C#(40ms) O(sqrt(N)) O(1)
1496 Path Crossing C#(72ms) O(N) O(N)

Problems 1501-1550

Back to Table of Contents

# Title Solutions Time Space Comments
1502 Can Make Arithmetic Progression From Sequence C#(92ms) O(N) O(1)
1504 Count Submatrices With All Ones C#(116ms) O(N*M) O(N*M)
1506 Find Root of N-Ary Tree C#(352ms) O(N) O(1)
1507 Reformat Date C#(88ms) O(N) O(N)
1508 Range Sum of Sorted Subarray Sums C#(388ms) O(N2) O(N2)
1512 Number of Good Pairs C#(92ms) O(N) O(N)
1518 Water Bottles C#(32ms) O(logkN) O(1)

About

The C# solutions for LeetCode problems.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%