Leetcode Solutions Swift
Leetcode solutions in Swift
Current Finished: 131
String(19)
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
3 Longest Substring without repeating characters | String | Medium | O(n) | O(n) |
14 Longest Common Prefix | String | Easy | O(nm) | O(mn) |
28 Implement strStr | String | Easy | O(n) | O(mn) |
49 Group Anagrams | String | Medium | O(Nmlgm) | O(N) |
58 Length of Last Word | String | Easy | O(n) | O(n) |
165 Compare Version Numbers | String | Easy | O(n) | O(n) |
205 Isomorphic Strings | String | Easy | O(n) | O(n) |
242 Valid Anagram | String | Easy | O(n) | O(n) |
293 Flip Game |
String | Easy | O(N) | O(N) |
294 Flip Game |
String | Medium | O(2^(n/2)) | O(2^(n/2)) |
290 Word Pattern | String | Easy | O(n) | O(n) |
340 Longest SubString with At Most K Distinct Characters |
String | Hard | O(1) | O(N) |
344 Reverse String | String | Easy | O(n) | O(n) |
345 Reverse Vowels of a String | String | Easy | O(n) | O(n) |
383 Ransom Note | String | Easy | O(n) | O(n) |
388 Longest Absolute File Path Solution | String | Medium | O(N) | O(N) |
389 Find the difference | String & hash table | Easy | O(n) | O(n) |
394 Decode String | String | Medium | O(N) | O(N) |
418 Sentence Screen Fitting |
String | Medium | O(1) | O(row * col) |
Array(22)
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
1 Two Sum | Array | Easy | O(n) | O(n) |
15 3Sum | Array | Medium | O(n) | O(n^2) |
18 4Sum | Array | Medium | O(N^2) | O(N^4) |
26 Remove Duplicates from sorted array | Array | Easy | O(N) | O(N) |
27 Remove Element | Array | Easy | O(1) | O(n) |
36 Valid Sudoku | Array | Easy | O(1) | O(1) |
48 Rotate Image | Array | Medium | O(1) | O(n^2) |
80 Remove Duplicates from sorted array II | Array | Medium | O(N) | O(N) |
189 Rotate Array | Array | Easy | O(1) | O(n) |
217 Contains Duplicate | Array | Easy | O(n) | O(n) |
228 Summary Ranges | Array | Medium | O(n) | O(n) |
260 Single Number III | Array/Bit | Medium | O(1) | O(n) |
283 Move Zeroes | Array | Easy | O(1) | O(n) |
303 Range Sum Query - Immutable | Array | Easy | O(N) | O(N) |
304 Range Sum Query 2D - Immutable | Array | Medium | O(N^2) | O(N^2) |
308 Range Sum Query 2D - Mutable | Array | Hard | O(N^2) | O(N^2) |
349 Intersection of two arrays | Array | Easy | O(n) | O(n) |
350 Intersection of two arrays II | Array | Easy | O(n) | O(n) |
361 Bomb Enemy |
Array | Medium | O(N) | O(MN) |
457 Circular Array Loop | Array | Medium | O(1) | O(N) |
621 Task Scheduler | Array | Medium | O(1) | O(N) |
645 Set Mismatch | Array | Medium | O(N) | O(N) |
Tree(20)
Graph(1)
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
207 Course Schedule | Graph | Medium | O( | V |
Search(9)
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
33 Search in rotated sorted array | Search | Hard | O(1) | O(lgn) |
34 Search for a Range | Search | Medium | O(1) | O(lgn) |
35 Search Insert Position | Search | Medium | O(1) | O(lgn) |
69 Sqrtx | Search | Medium | O(1) | O(lgn) |
81 Search in rotated sorted array II | Search | Medium | O(1) | O(n) |
153 Find Minimum in Rotated Sorted Array | Search | Medium | O(1) | O(lgn) |
154 Find Minimum in Rotated Sorted Array II | Search | Medium | O(1) | O(n) |
162 Find Peak Element | Search | Medium | O(1) | O(lgn) |
278 First Bad Version | Binary Search | Easy | O(1) | O(lgn) |
Linked List(8)
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
2 Add Two Numbers | LinkedList | Medium | O(n) | O(n) |
24 Swap Nodes in Pairs | Linked List | Easy | O(1) | O(n) |
61 Rotate List | Linked List | Medium | O(1) | O(N) |
83 Remove Duplicates From Sorted List | Linked List | Easy | O(1) | O(N) |
86 Partition List | Linked List | Medium | O(1) | O(N) |
141 Reorder List | Linked List | Medium | O(1) | O(N) |
206 Reverse LinkedList | Linked List | Easy | O(1) | O(N) |
445 Add Two Numbers II | Linked List | Medium | O(1) | O(N) |
DynamicProgramming(18)
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
5 Longest Palindromic Substring | DP | Medium | O(n^2) | O(n^2) |
53 Maximum Subarray | DP | Medium | O(n) | O(n) |
55 Jump Game | DP | Medium | O(n) | O(n) |
62 Unique Paths | DP | Medium | O(mn) | O(mn) |
63 Unique Paths II | DP | Medium | O(mn) | O(mn) |
64 Minimum Path Sum | DP | Medium | O(mn) | O(mn) |
70 Climbing Stairs | DP | Easy | O(1) | O(N) |
72 Edit Distance | DP | Hard | O(NM) | O(NM) |
121 Best Time to Buy and Sell Stock | DP | Easy | O(1) | O(N) |
139 Word Break | DP | Medium | O(n) | O(nL^2) |
152 Maximum Product Subarray | DP | Medium | O(1) | O(n) |
198 House Robber | DP | Easy | O(n) | O(n) |
213 House Robber II | DP | Medium | O(n) | O(n) |
221 Maximal Square | DP | Medium | O(MN) | O(MN) |
279 Unique Paths II | DP | Medium | O(n) | O(n^2) |
300 Longest Increasing Subsequence | DP | Medium | O(n) | O(n^2) |
322 Coin Change | DP | Medium | O(n^2) | O(n) |
377 Combination Sum IV | Dynamic Programming | Medium | O(N) | O(n^(target/min(n))) |
Stack(7)
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
20 Valid Parentheses | Stack | Easy | O(N) | O(N) |
94 Binary Tree In order Traversal | Stack | Medium | O(N) | O(N) |
144 Binary Tree Preorder Traversal | Stack | Medium | O(N) | O(N) |
145 Binary Tree Post Order Traversal | Stack | Hard | O(N) | O(N) |
224 Basic Calculator | Stack | Hard | O(N) | O(N) |
227 Basic Calculator II | Stack | Medium | O(N) | O(N) |
772 Basic Calculator III | Stack | Hard | O(N) | O(N) |
Heap(2)
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
23 Merge K Sorted Lists | Heap | Hard | O(N) | O(Nlgk) |
295 Find Median From Data Stream | Heap | Hard | O(N) | O(1) |
Queue(1)
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
346 Moving Average from Data Stream |
Queue | Easy | O(N) | O(1) |
Sort(3)
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
75 Sort Colors | Sort | Medium | O(NlgN) | O(N) |
347 Top K Frequent Element | Sort | Medium | O(klgk) | O(N) |
56 Merge Intervals | Sort | Medium | O(NlgN) | O(N) |
DFS(8)
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
46 Permutations | DFS | Medium | O(N!) | O(N!) |
47 Permutations II | DFS | Medium | O(N!) | O(N!) |
77 Combinations | DFS | Medium | O(N^K) | O(K*N^K) |
78 Subsets | DFS | Medium | O(2^N) | O(2^N) |
79 Word Search | DFS | Medium | O(3^N) | O(N^2) |
90 Subsets II | DFS | Medium | O(2^N) | O(2^N) |
212 Word Search II | DFS | Hard | O(N*3^N) | O(N^2) |
638 ShoppingOffers | DFS | Medium | O(N) | O(N^2) |
BFS(1)
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
317 Shortest Distance from All Buildings |
BFS | Easy | O(MN) | O(KMN) |
Math(11)
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
7 Reverse Integer | Math | Easy | O(1) | O(1) |
8 String to Integer(atoi) | Math String | Easy | O(n) | O(1) |
9 Palindrome Number | Math | Easy | O(1) | O(1) |
136 Single Number | Math | Easy | O(1) | O(n) |
223 Rectangle Area | Math | Easy | O(1) | O(1) |
231 Power of Two | Math | Easy | O(1) | O(1) |
258 Add Digits | Math | Easy | O(1) | O(1) |
263 Ugly Number | Math | Easy | O(1) | O(1) |
326 Power of Three | Math | Easy | O(1) | O(1) |
338 Counting Bits | Math | Medium | O(N) | O(N) |
400 Nth Digit | Math | Easy | O(lgN) | O(1) |
[Google]
Problem | Category | Difficulty | Space | Time |
---|---|---|---|---|
294 Flip Game |
String | Medium | O(2^(n/2)) | O(2^(n/2)) |
308 Range Sum Query 2D - Mutable | Array | Hard | O(N^2) | O(N^2) |
317 Shortest Distance from All Buildings |
BFS | Easy | O(MN) | O(KMN) |
340 Longest SubString with At Most K Distinct Characters |
String | Hard | O(1) | O(N) |
346 Moving Average from Data Stream |
Queue | Easy | O(N) | O(1) |
361 Bomb Enemy |
Array | Medium | O(N) | O(MN) |
388 Longest Absolute File Path Solution | String | Medium | O(N) | O(N) |
394 Decode String | String | Medium | O(N) | O(N) |
418 Sentence Screen Fitting |
String | Medium | O(1) | O(row * col) |
482 LicenseKey Formatting Solution | String | Medium | O(n) | O(n) |