LeetCode by Swift

LeetCode Online Judge is a website containing many algorithm questions. Most of them are real interview questions of Google, Facebook, LinkedIn, Apple, etc. This repo shows my solutions by Swift with the code style strictly follows the RayWenderlich Swift Style Guide. Please feel free to reference and STAR to support this repo, thank you!

Leetcode

Progress

Problem Status shows the latest progress to all 1000+ questions. Currently we have 323 completed solutions. Note: questions with

mark means that you have to Subscript to premium membership of LeetCode to unlock them.

Contributors

Data Structures

Companies

Array

Title Solution Difficulty Time Space
Verify an Alien Dictionary Swift Easy O(n) O(n)
Sort Array By Parity Swift Easy O(n) O(n)
Max Consecutive Ones Swift Easy O(n) O(1)
Heaters Swift Easy O(nlogn) O(1)
Number of Boomerangs Swift Easy O(n ^ 2) O(n)
Island Perimeter Swift Easy O(nm) O(1)
Majority Element Swift Easy O(n) O(1)
Majority Element II Swift Medium O(n) O(1)
First Missing Positive Swift Hard O(n) O(n)
Intersection of Two Arrays Swift Easy O(n) O(n)
Intersection of Two Arrays II Swift Easy O(n) O(n)
Contains Duplicate Swift Easy O(n) O(n)
Contains Duplicate II Swift Easy O(n) O(n)
Remove Duplicates from Sorted Array Swift Easy O(n) O(1)
Remove Duplicates from Sorted Array II Swift Medium O(n) O(1)
Move Zeroes Swift Easy O(n) O(1)
Remove Element Swift Easy O(n) O(1)
Strobogrammatic Number Swift Easy O(n) O(1)
Can Place Flowers Swift Easy O(n) O(1)
Two Sum Swift Easy O(n) O(n)
Two Sum II – Input array is sorted Swift Easy O(n) O(1)
Two Sum III – Data structure design Swift Easy O(n) O(1)
Two Sum Less Than K Swift Easy O(nlogn) O(n)
3Sum Swift Medium O(n^2) O(nC3)
3Sum Closest Swift Medium O(n^2) O(nC3)
4Sum Swift Medium O(n^3) O(nC4)
Increasing Triplet Subsequence Swift Medium O(n) O(1)
Summary Ranges Swift Medium O(n) O(n)
Range Sum Query 2D – Immutable Swift Medium O(mn) O(mn)
Missing Ranges Swift Medium O(n) O(1)
Asteroid Collision Swift Medium O(n) O(n)
Maximize Distance to Closest Person Swift Easy O(n) O(1)
Exam Room Swift Medium O(n) O(n)
Shortest Word Distance Swift Easy O(n) O(1)
Shortest Word Distance II Swift Medium O(n) O(n)
Shortest Word Distance III Swift Medium O(n) O(1)
Minimum Size Subarray Sum Swift Medium O(n) O(1)
Maximum Size Subarray Sum Equals k Swift Medium O(n) O(n)
Smallest Range Swift Hard O(nm) O(nm)
Product of Array Except Self Swift Medium O(n) O(1)
Rotate Array Swift Easy O(n) O(1)
Rotate Image Swift Medium O(n^2) O(1)
Spiral Matrix Swift Medium O(n^2) O(1)
Spiral Matrix II Swift Medium O(n^2) O(1)
Diagonal Traverse Swift Medium O(mn) O(1)
Valid Sudoku Swift Easy O(n^2) O(n)
Set Matrix Zero Swift Medium O(n^2) O(1)
Next Permutation Swift Medium O(n) O(1)
Gas Station Swift Medium O(n) O(1)
Game of Life Swift Medium O(n) O(1)
Task Scheduler Swift Medium O(nlogn) O(n)
Validate IP Address Swift Medium O(n) O(1)
Sliding Window Maximum Swift Hard O(n) O(n)
Longest Consecutive Sequence Swift Hard O(n) O(n)
Create Maximum Number Swift Hard O(n^2) O(n)
Find All Numbers Disappeared in an Array Swift Easy O(n) O(1)

String

Title Solution Difficulty Time Space
Fizz Buzz Swift Easy O(n) O(1)
First Unique Character in a String Swift Easy O(n) O(1)
Keyboard Row Swift Easy O(nm) O(n)
Valid Word Abbreviation Swift Easy O(n) O(n)
Valid Palindrome Swift Easy O(n) O(n)
Valid Palindrome II Swift Easy O(n) O(n)
Detect Capital Swift Easy O(n) O(1)
Count and Say Swift Easy O(n^2) O(1)
Flip Game Swift Easy O(n) O(n)
Implement strStr() Swift Easy O(nm) O(n)
Isomorphic Strings Swift Easy O(n) O(n)
Reverse String Swift Easy O(n) O(n)
Reverse String II Swift Easy O(n) O(n)
Reverse Vowels of a String Swift Easy O(n) O(n)
Reverse Words in a String Swift Medium O(n) O(1)
Reverse Words in a String II Swift Medium O(n) O(1)
Reverse Words in a String III Swift Easy O(n) O(1)
Length of Last Word Swift Easy O(n) O(n)
String Compression Swift Easy O(n) O(1)
Add Strings Swift Easy O(n) O(1)
Shortest Distance to a Character Swift Easy O(n) O(1)
Multiply Strings Swift Medium O(n) O(1)
Palindrome Permutation Swift Easy O(n) O(n)
Valid Anagram Swift Easy O(n) O(n)
Ransom Note Swift Easy O(n) O(n)
Group Anagrams Swift Medium O(nmlogm + nlogn) O(n)
Find Duplicate File in System Swift Medium O(nm) O(n)
Longest Common Prefix Swift Easy O(nm) O(m)
Longest Substring Without Repeating Characters Swift Medium O(n) O(n)
One Edit Distance Swift Medium O(n) O(n)
Word Pattern Swift Easy O(n) O(n)
Permutation in String Swift Medium O(nm) O(n)
Find All Anagrams in a String Swift Medium O(n) O(n)
Minimum Window Substring Swift Hard O(n^2) O(n)
Longest Substring with At Most Two Distinct Characters Swift Hard O(n) O(n)
Longest Substring with At Most K Distinct Characters Swift Hard O(n) O(n)
Text Justification Swift Hard O(n) O(n)
Find the Closest Palindrome Swift Hard O(n) O(n)

Linked List

Title Solution Difficulty Time Space
Reverse Linked List Swift Easy O(n) O(1)
Palindrome Linked List Swift Easy O(n) O(1)
Swap Nodes in Pairs Swift Easy O(n) O(1)
Remove Linked List Elements Swift Easy O(n) O(1)
Remove Duplicates from Sorted List Swift Easy O(n) O(1)
Remove Duplicates from Sorted List II Swift Medium O(n) O(1)
Remove Nth Node From End of List Swift Easy O(n) O(1)
Odd Even Linked List Swift Medium O(n) O(1)
Rotate List Swift Medium O(n) O(1)
Reorder List Swift Medium O(n) O(1)
Merge Two Sorted Lists Swift Easy O(n) O(1)
Merge k Sorted Lists Swift Hard O(mlogn) O(1)
Partition List Swift Medium O(n) O(1)
LRU Cache Swift Hard O(1) O(1)
LFU Cache Swift Hard O(1) O(1)

Stack

Title Solution Difficulty Time Space
Min Stack Swift Easy O(1) O(n)
Max Stack Swift Easy O(n) O(n)
Valid Parentheses Swift Easy O(n) O(n)
Longest Valid Parentheses Swift Hard O(n) O(n)
Evaluate Reverse Polish Notation Swift Medium O(n) O(n)
Exclusive Time of Functions Swift Medium O(n) O(n)
Simplify Path Swift Medium O(n) O(n)
Remove K Digits Swift Medium O(n) O(n)
Ternary Expression Parser Swift Medium O(n) O(n)
Binary Tree Preorder Traversal Swift Medium O(n) O(n)
Binary Tree Inorder Traversal Swift Medium O(n) O(n)
Binary Search Tree Iterator Swift Medium O(n) O(n)
Binary Tree Postorder Traversal Swift Hard O(n) O(n)
Decode String Swift Medium O(n) O(n)
Basic Calculator Swift Hard O(n) O(n)

Queue

Title Solution Difficulty Time Space
Implement Queue using Stacks Swift Easy O(n) O(n)

Tree

Title Solution Difficulty Time Space
Same Tree Swift Easy O(n) O(n)
Symmetric Tree Swift Easy O(n) O(n)
Invert Binary Tree Swift Easy O(n) O(n)
Binary Tree Upside Down Swift Medium O(n) O(1)
Minimum Depth of Binary Tree Swift Easy O(n) O(1)
Maximum Depth of Binary Tree Swift Easy O(n) O(1)
Diameter of Binary Tree Swift Easy O(n) O(1)
Balanced Binary Tree Swift Easy O(n) O(n)
Sum of Left Leaves Swift Easy O(n) O(1)
Flatten Binary Tree to Linked List Swift Medium O(n) O(1)
Convert Sorted Array to Binary Search Tree Swift Easy O(n) O(1)
Validate Binary Search Tree Swift Medium O(n) O(log n)
Binary Tree Level Order Traversal Swift Easy O(n) O(n)
Binary Tree Level Order Traversal II Swift Easy O(n) O(n)
Merge Two Binary Trees Swift Easy O(n) O(n)
Binary Tree Zigzag Level Order Traversal Swift Medium O(n) O(n)
Binary Tree Vertical Order Traversal Swift Medium O(n) O(n)
Kth Smallest Element in a BST Swift Medium O(n) O(n)
Binary Tree Right Side View Swift Medium O(n) O(n)
Construct Binary Tree from Preorder and Inorder Traversal Swift Medium O(nlogn) O(1)
Construct Binary Tree from Inorder and Postorder Traversal Swift Medium O(nlogn) O(1)
Path Sum Swift Easy O(n) O(n)
Path Sum II Swift Medium O(n) O(n)
Path Sum III Swift Easy O(n^2) O(1)
Bnary Tree Paths Swift Easy O(n) O(n)
Binary Tree Maximum Path Sum Swift Hard O(n) O(1)
House Robber III Swift Medium O(n) O(1)
Unique Binary Search Trees Swift Medium O(n^2) O(n)
Recover Binary Search Tree Swift Hard O(n) O(1)
Serialize and Deserialize Binary Tree Swift Hard O(n) O(n)
Serialize and Deserialize N-ary Tree Swift Hard O(n) O(n)

Dynamic programming

Title Solution Difficulty Time Space
Nested List Weight Sum Swift Easy O(n) O(1)
Climbing Stairs Swift Easy O(n) O(1)
Min Cost Climbing Stairs Swift Easy O(n) O(n)
Unique Paths Swift Medium O(mn) O(mn)
Unique Paths II Swift Medium O(mn) O(mn)
Nested List Weight Sum II Swift Medium O(n) O(n)
Flip Game II Swift Medium O(n) O(n)
Can I Win Swift Medium O(2^n) O(n)
Decode Ways Swift Medium O(n) O(n)
Minimum Path Sum Swift Medium O(mn) O(mn)
Generate Parentheses Swift Medium O(2^n) O(n)
Different Ways to Add Parentheses Swift Medium O(n^n) O(n)
Best Time to Buy and Sell Stock Swift Easy O(n) O(1)
Best Time to Buy and Sell Stock II Swift Medium O(n) O(1)
Best Time to Buy and Sell Stock III Swift Hard O(n) O(n)
Best Time to Buy and Sell Stock IV Swift Hard O(n^2) O(n)
Best Time to Buy and Sell Stock with Cooldown Swift Medium O(n^2) O(n)
Maximum Sum of 3 Non-Overlapping Subarrays Swift Hard O(n) O(n)
Coin Change Swift Medium O(n^2) O(n)
Coin Change II Swift Medium O(n^2) O(n)
Paint House Swift Easy O(n) O(n)
Paint House II Swift Hard O(n) O(1)
Longest Increasing Subsequence Swift Medium O(nlogn) O(n)
Palindromic Substrings Swift Medium O(n^2) O(n^2)
Longest Palindromic Substring Swift Medium O(n^2) O(n^2)
Perfect Squares Swift Medium O(n^2) O(n)
House Robber Swift Easy O(n) O(1)
House Robber II Swift Medium O(n) O(1)
Paint Fence Swift Easy O(n) O(n)
Maximum Subarray Swift Medium O(n) O(1)
Maximum Product Subarray Swift Medium O(n) O(1)
Maximal Square Swift Medium O(mn) O(mn)
Edit Distance Swift Hard O(mn) O(mn)
Combination Sum IV Swift Medium O(2^n) O(n)
Triangle Swift Medium O(2^n) O(m)
Wiggle Subsequence Swift Medium O(n) O(1)
Wildcard Matching Swift Hard O(mn) O(mn)
Regular Expression Matching Swift Hard O(mn) O(mn)
Minimum Window Subsequence Swift Hard O(mn) O(mn)
Guess Number Higher or Lower II Swift Medium O(nlogn) O(n^2)
Burst Ballons Swift Hard O(n^3) O(n)
Frog Jump Swift Hard O(n^2) O(n)
Jump Game Swift Medium O(n) O(1)
Dungeon Game Swift Hard O(nm) O(nm)

Depth-first search

Title Solution Difficulty Time Space
Permutations Swift Medium O(n^n) O(n)
Permutations II Swift Medium O(n^n) O(n)
Subsets Swift Medium O(n^n) O(n)
Subsets II Swift Medium O(n^n) O(n)
Combinations Swift Medium O(n^n) O(n)
Combination Sum Swift Medium O(n^n) O(2^n – 1)
Combination Sum II Swift Medium O(n^n) O(2^n – 2)
Combination Sum III Swift Medium O(n^n) O(nCk)
Letter Combinations of a Phone Number Swift Medium O(4^n) O(n)
Factor Combinations Swift Medium O(n^n)) O(2^n – 1)
Strobogrammatic Number II Swift Medium O(m^n) O(n)
Generalized Abbreviation Swift Medium O(n^n) O(2^n)
Palindrome Partitioning Swift Medium O(n^n) O(n)
Is Graph Bipartite Swift Medium O(n) O(n)
Number of Islands Swift Medium O((mn)^2) O(1)
Walls and Gates Swift Medium O(n^n) O(2^n)
Word Search Swift Medium O((mn * 4 ^ (k – 1)) O(mn)
Word Search II Swift Hard O(((mn)^2)) O(n^2)
Add and Search Word – Data structure design Swift Medium O(n) O(n)
Partition to K Equal Sum Subsets Swift Medium O(k^n) O(n)
N-Queens Swift Hard O((n^n)) O(n^2)
N-Queens II Swift Hard O((n^n)) O(n)
Word Squares Swift Hard O((n^2)) O(n^2)
Word Pattern II Swift Hard O(n^n) O(n)
Sudoku Solver Swift Hard O(n^4) O(1)
Remove Invalid Parentheses Swift Hard O(n^n) O(n)
Expression Add Operators Swift Hard O(n^n) O(n)

Breadth-first search

Title Solution Difficulty Time Space
Word Ladder Swift Medium O(nm) O(nm)
Evaluate Division Swift Medium O(n^2) O(n)
Shortest Distance from All Buildings Swift Hard O((mn)^2) O(mn)

Math

Title Solution Difficulty Time Space
Add Binary Swift Easy O(n) O(n)
Add Two Numbers Swift Medium O(n) O(1)
Add Digits Swift Easy O(1) O(1)
Plus One Swift Easy O(n) O(1)
Missing Number Swift Easy O(n) O(1)
Divide Two Integers Swift Medium O(logn) O(1)
Number Complement Swift Easy O(n) O(1)
Hamming Distance Swift Easy O(n) O(1)
Integer Break Swift Medium O(logn) O(1)
Factorial Trailing Zeroes Swift Medium O(logn) O(1)
Happy Number Swift Easy O(n) O(n)
Single Number Swift Medium O(n) O(1)
Ugly Number Swift Easy O(logn) O(1)
Ugly Number II Swift Medium O(n) O(n)
Super Ugly Number Swift Medium O(n^2) O(n)
Count Primes Swift Easy O(n) O(n)
String to Integer (atoi) Swift Easy O(n) O(1)
Fraction to Recurring Decimal Swift Medium O(logn) O(n)
Pow(x, n) Swift Medium O(logn) O(1)
Power of Two Swift Easy O(1) O(1)
Power of Three Swift Easy O(1) O(1)
Super Power Swift Medium O(n) O(1)
Sum of Two Integers Swift Easy O(n) O(1)
Reverse Integer Swift Easy O(n) O(1)
Excel Sheet Column Number Swift Easy O(n) O(1)
Integer to Roman Swift Medium O(n) O(1)
Roman to Integer Swift Easy O(n) O(n)
Integer to English Words Swift Hard O(n) O(1)
Sparse Matrix Multiplication Swift Medium O(n^3) O(n^2)
Rectangle Area Swift Easy O(1) O(1)
Minimum Moves to Equal Array Elements Swift Easy O(n) O(1)
Trapping Rain Water Swift Hard O(n) O(n)
Container With Most Water Swift Medium O(n) O(1)
Counting Bits Swift Medium O(n) O(n)
K-th Smallest in Lexicographical Order Swift Hard O(n) O(1)
Gary Code Swift Medium O(n) O(2^n)
Permutation Sequence Swift Medium O(n^2) O(1)
Line Reflection Swift Medium O(n) O(n)
Valid Number Swift Hard O(n) O(1)

Search

Title Solution Difficulty Time Space
Closest Binary Search Tree Value Swift Easy O(logn) O(1)
Closest Binary Search Tree Value II Swift Hard O(n) O(n)
Search in Rotated Sorted Array Swift Hard O(logn) O(1)
Search in Rotated Sorted Array II Swift Medium O(logn) O(1)
Find Minimum in Rotated Sorted Array Swift Medium O(logn) O(1)
Find Minimum in Rotated Sorted Array II Swift Hard O(logn) O(1)
Search a 2D Matrix Swift Medium O(log(m + n)) O(1)
Search a 2D Matrix II Swift Medium O(m + n) O(1)
Search for a Range Swift Medium O(logn) O(1)
Search Insert Position Swift Medium O(logn) O(1)
Peak Index in a Mountain Array Swift Easy O(logn) O(1)
Find Peak Element Swift Medium O(logn) O(1)
Random Pick with Weight Swift Medium O(logn) O(1)
Sqrt(x) Swift Medium O(logn) O(1)
Median of Two Sorted Arrays Swift Hard O(log(m + n)) O(1)
Minimize Max Distance to Gas Station Swift Hard O(nlogm) O(1)

Sort

Title Solution Difficulty Time Space
Merge Sorted Array Swift Easy O(n) O(1)
Sort Colors Swift Medium O(n) O(1)
Wiggle Sort Swift Medium O(n) O(1)
Wiggle Sort II Swift Medium O(nlogn) O(n)
Sort Transformed Array Swift Medium O(n) O(1)
Top K Frequent Elements Swift Medium O(nlogn) O(n)
Meeting Rooms Swift Easy O(nlogn) O(1)
Meeting Rooms II Swift Medium O(nlogn) O(n)
Merge Intervals Swift Hard O(nlogn) O(n)
Alien Dictionary Swift Hard O(nm) O(nm)
Kth Largest Element in an Array Swift Medium O(nlogn) O(n)
Array Partition I Swift Easy O(nlogn) O(n)
Insert Interval Swift Hard O(n) O(1)
Largest Number Swift Medium O(nlogn) O(1)

Graph

Title Solution Difficulty Time Space
Number of Connected Components in an Undirected Graph Swift Medium O(nlogn) O(n)
Graph Valid Tree Swift Medium O(nlogn) O(n)
Number of Islands II Swift Hard O(klogmn) O(mn)
Course Schedule Swift Medium O(n) O(n)
Course Schedule II Swift Medium O(n) O(n)

Design

Title Solution Difficulty Time Space
Shuffle an Array Swift Easy O(n) O(1)
Design HashMap Swift Easy O(n) O(n)
Design Tic-Tac-Toe Swift Medium O(1) O(n)
Flatten Nested List Iterator Swift Medium O(n) O(n)
Flatten 2D Vector Swift Medium O(n) O(n)
Implement Trie (Prefix Tree) Swift Medium O(n) O(n)
Add and Search Word – Data structure design Swift Medium O(24^n) O(n)
Insert Delete GetRandom O(1) Swift Medium O(1) O(n)
LRU Cache Swift Hard O(1) O(n)
All O`one Data Structure Swift Hard O(1) O(n)

Google

Title Solution Difficulty Frequency
Plus One Swift Easy ★★★★★★
Number of Islands Swift Medium ★★★★
Summary Ranges Swift Medium ★★★★
Perfect Squares Swift Medium ★★★★
Merge Intervals Swift Hard ★★★
Valid Parentheses Swift Easy ★★★
Trapping Rain Water Swift Hard ★★
Merge k Sorted Lists Swift Hard ★★
Longest Consecutive Sequence Swift Hard ★★
Find Peak Element Swift Medium ★★
Power of Two Swift Easy ★★
Spiral Matrix Swift Medium ★★
Sliding Window Maximum Swift Hard ★★
Pow(x, n) Swift Medium ★★
Letter Combinations of a Phone Number Swift Medium ★★
Heaters Swift Easy

Facebook

Title Solution Difficulty Frequency
3Sum Swift Medium ★★★★★★
Valid Palindrome Swift Easy ★★★★★★
Valid Palindrome II Swift Easy ★★★★★★
Move Zeroes Swift Easy ★★★★★★
Remove Invalid Parentheses Swift Hard ★★★★★★
Add Binary Swift Easy ★★★★★
Two Sum Swift Easy ★★★★★
Bnary Tree Paths Swift Easy ★★★★
Letter Combinations of a Phone Number Swift Medium ★★★★
Merge k Sorted Lists Swift Hard ★★★★
Reverse Linked List Swift Easy ★★★
Merge Intervals Swift Hard ★★★
Number of Islands Swift Medium ★★★
Reverse Linked List Swift Easy ★★★
Expression Add Operators Swift Hard ★★★
Subsets Swift Medium ★★★
Sort Colors Swift Medium ★★

Snapchat

Title Solution Difficulty Frequency
Game of Life Swift Medium ★★★★★★
Meeting Rooms II Swift Medium ★★★★★★
Valid Sudoku Swift Easy ★★★★★
Binary Tree Vertical Order Traversal Swift Medium ★★★★
Alien Dictionary Swift Hard ★★★★
One Edit Distance Swift Medium ★★★
Sudoku Solver Swift Hard ★★★
Reverse Linked List Swift Easy ★★
Unique Binary Search Trees Swift Medium ★★
Minimum Window Substring Swift Hard ★★
Remove K Digits Swift Medium
Ternary Expression Parser Swift Medium

Uber

Title Solution Difficulty Frequency
Valid Sudoku Swift Easy ★★★★
Spiral Matrix Swift Medium ★★★★
Letter Combinations of a Phone Number Swift Medium ★★★★
Group Anagrams Swift Medium ★★★★
Word Pattern Swift Easy ★★★
Roman to Integer Swift Easy ★★★
Combination Sum Swift Medium ★★

Airbnb

Title Solution Difficulty Frequency
Two Sum Swift Easy ★★★★★
Text Justification Swift Hard ★★★★
House Robber Swift Easy ★★
Single Number Swift Medium ★★
Word Search II Swift Hard ★★
Add Two Numbers Swift Medium ★★

LinkedIn

Title Solution Difficulty Frequency
Maximum Subarray Swift Medium ★★★★★★
Pow(x, n) Swift Medium ★★★★★★
Merge Intervals Swift Hard ★★★★★★
Isomorphic Strings Swift Easy ★★★★★★
Search in Rotated Sorted Array Swift Hard ★★★★★
Search for a Range Swift Medium ★★★★★
Two Sum Swift Easy ★★★★
Binary Tree Level Order Traversal Swift Easy ★★★★
Evaluate Reverse Polish Notation Swift Medium ★★★
Maximum Product Subarray Swift Medium ★★★
Product of Array Except Self Swift Medium ★★★
Symmetric Tree Swift Easy ★★

Amazon

Title Solution Difficulty Frequency
Two Sum Swift Easy ★★★★★★
Min Cost Climbing Stairs Swift Easy ★★★★
Number of Islands Swift Medium ★★
Add Two Numbers Swift Medium ★★
Reverse Linked List Swift Easy ★★
Valid Parentheses Swift Easy ★★
Longest Palindromic Substring Swift Medium ★★
Trapping Rain Water Swift Hard ★★
Longest Substring Without Repeating Characters Swift Medium ★★
Letter Combinations of a Phone Number Swift Medium ★★
Valid Anagram Swift Easy ★★
Rotate Image Swift Medium ★★
Best Time to Buy and Sell Stock Swift Easy ★★
3Sum Swift Medium ★★
Sliding Window Maximum Swift Hard ★★

Microsoft

Title Solution Difficulty Frequency
Reverse Linked List Swift Easy ★★★★★★
Two Sum Swift Easy ★★★★★
String to Integer (atoi) Swift Easy ★★★★
Add Two Numbers Swift Medium ★★★★
Excel Sheet Column Number Swift Easy ★★★★
Validate Binary Search Tree Swift Medium ★★★
Merge Two Sorted Lists Swift Easy ★★★

Problem Status

Solution Number Title Difficulty
Swift 460 LFU Cache Hard
Swift 448 Find All Numbers Disappeared in an Array Easy
Swift 377 Combination Sum IV Medium
376 Wiggle Subsequence Medium
Swift 375 Guess Number Higher or Lower II Medium
374 Guess Number Higher or Lower Easy
373 Find K Pairs with Smallest Sums Medium
Swift 372 Super Pow Medium
Swift 371 Sum of Two Integers Easy
370 Range Addition
Medium
369 Plus One Linked List
Medium
368 Largest Divisible Subset Medium
367 Valid Perfect Square Medium
366 Find Leaves of Binary Tree
Medium
365 Water and Jug Problem Medium
Swift 364 Nested List Weight Sum II
Medium
363 Max Sum of Rectangle No Larger Than K Hard
362 Design Hit Counter
Medium
361 Bomb Enemy
Medium
Swift 360 Sort Transformed Array
Medium
359 Logger Rate Limiter
Easy
358 Rearrange String k Distance Apart
Hard
357 Count Numbers with Unique Digits Medium
356 Line Reflection
Medium
355 Design Twitter Medium
354 Russian Doll Envelopes Hard
353 Design Snake Game
Medium
352 Data Stream as Disjoint Intervals Hard
351 Android Unlock Patterns
Medium
Swift 350 Intersection of Two Arrays II Easy
Swift 349 Intersection of Two Arrays Easy
348 Design Tic-Tac-Toe
Medium
Swift 347 Top K Frequent Elements Medium
346 Moving Average from Data Stream
Easy
Swift 345 Reverse Vowels of a String Easy
Swift 344 Reverse String Easy
Swift 343 Integer Break Medium
342 Power of Four Easy
Swift 341 Flatten Nested List Iterator Medium
Swift 340 Longest Substring with At Most K Distinct Characters
Hard
Swift 339 Nested List Weight Sum
Easy
Swift 338 Counting Bits Medium
Swift 337 House Robber III Medium
336 Palindrome Pairs Hard
335 Self Crossing Hard
Swift 334 Increasing Triplet Subsequence Medium
333 Largest BST Subtree
Medium
332 Reconstruct Itinerary Medium
331 Verify Preorder Serialization of a Binary Tree Medium
330 Patching Array Hard
329 Longest Increasing Path in a Matrix Hard
Swift 328 Odd Even Linked List Medium
327 Count of Range Sum Hard
Swift 326 Power of Three Easy
Swift 325 Maximum Size Subarray Sum Equals k
Medium
Swift 324 Wiggle Sort II Medium
Swift 323 Number of Connected Components in an Undirected Graph
Medium
Swift 322 Coin Change Medium
Swift 321 Create Maximum Number Hard
Swift 320 Generalized Abbreviation
Medium
319 Bulb Switcher Medium
318 Maximum Product of Word Lengths Medium
Swift 317 Shortest Distance from All Buildings
Hard
316 Remove Duplicate Letters Hard
315 Count of Smaller Numbers After Self Hard
Swift 314 Binary Tree Vertical Order Traversal
Medium
Swift 313 Super Ugly Number Medium
Swift 312 Burst Balloons Hard
Swift 311 Sparse Matrix Multiplication
Medium
310 Minimum Height Trees Medium
Swift 309 Best Time to Buy and Sell Stock with Cooldown Medium
308 Range Sum Query 2D – Mutable
Hard
307 Range Sum Query – Mutable Medium
306 Additive Number Medium
Swift 305 Number of Islands II
Hard
Swift 304 Range Sum Query 2D – Immutable Medium
303 Range Sum Query – Immutable Easy
302 Smallest Rectangle Enclosing Black Pixels
Hard
Swift 301 Remove Invalid Parentheses Hard
Swift 300 Longest Increasing Subsequence Medium
299 Bulls and Cows Easy
298 Binary Tree Longest Consecutive Sequence
Medium
297 Serialize and Deserialize Binary Tree Hard
Swift 296 Best Meeting Point
Hard
295 Find Median from Data Stream Hard
Swift 294 Flip Game II
Medium
Swift 293 Flip Game
Easy
292 Nim Game Easy
291 Word Pattern II
Hard
Swift 290 Word Pattern Easy
Swift 289 Game of Life Medium
288 Unique Word Abbreviation
Easy
287 Find the Duplicate Number Hard
Swift 286 Walls and Gates
Medium
285 Inorder Successor in BST
Medium
284 Peeking Iterator Medium
Swift 283 Move Zeroes Easy
Swift 282 Expression Add Operators Hard
281 Zigzag Iterator
Medium
Swift 280 Wiggle Sort
Medium
Swift 279 Perfect Squares Medium
278 First Bad Version Easy
277 Find the Celebrity
Medium
Swift 276 Paint Fence
Easy
275 H-Index II Medium
274 H-Index Medium
Swift 273 Integer to English Words Hard
Swift 272 Closest Binary Search Tree Value II
Hard
271 Encode and Decode Strings
Medium
Swift 270 Closest Binary Search Tree Value
Easy
Swift 269 Alien Dictionary
Hard
Swift 268 Missing Number Easy
267 Palindrome Permutation II
Medium
Swift 266 Palindrome Permutation
Easy
Swift 265 Paint House II
Hard
Swift 264 Ugly Number II Medium
Swift 263 Ugly Number Easy
Swift 261 Graph Valid Tree
Medium
260 Single Number III Medium
259 3Sum Smaller
Medium
Swift 258 Add Digits Easy
Swift 257 Binary Tree Paths Easy
Swift 256 Paint House
Medium
255 Verify Preorder Sequence in Binary Search Tree
Medium
Swift 254 Factor Combinations
Medium
Swift 253 Meeting Rooms II
Medium
Swift 252 Meeting Rooms
Easy
Swift 251 Flatten 2D Vector
Medium
250 Count Univalue Subtrees
Medium
249 Group Shifted Strings
Easy
248 Strobogrammatic Number III
Hard
Swift 247 Strobogrammatic Number II
Medium
Swift 246 Strobogrammatic Number
Easy
Swift 245 Shortest Word Distance III
Medium
Swift 244 Shortest Word Distance II
Medium
Swift 243 Shortest Word Distance
Easy
Swift 242 Valid Anagram Easy
Swift 241 Different Ways to Add Parentheses Medium
Swift 240 Search a 2D Matrix II Medium
Swift 239 Sliding Window Maximum Hard
Swift 238 Product of Array Except Self Medium
237 Delete Node in a Linked List Easy
236 Lowest Common Ancestor of a Binary Tree Medium
235 Lowest Common Ancestor of a Binary Search Tree Easy
Swift 234 Palindrome Linked List Easy
233 Number of Digit One Hard
Swift 232 Implement Queue using Stacks Easy
Swift 231 Power of Two Easy
Swift 230 Kth Smallest Element in a BST Medium
Swift 229 Majority Element II Medium
Swift 228 Summary Ranges Medium
227 Basic Calculator II Medium
Swift 226 Invert Binary Tree Easy
225 Implement Stack using Queues Easy
Swift 224 Basic Calculator Hard
Swift 223 Rectangle Area Easy
222 Count Complete Tree Nodes Medium
Swift 221 Maximal Square Medium
220 Contains Duplicate III Medium
Swift 219 Contains Duplicate II Easy
218 The Skyline Problem Hard
Swift 217 Contains Duplicate Easy
Swift 216 Combination Sum III Medium
Swift 215 Kth Largest Element in an Array Medium
214 Shortest Palindrome Hard
Swift 213 House Robber II Medium
Swift 212 Word Search II Hard
Swift 211 Add and Search Word – Data structure design Medium
Swift 210 Course Schedule II Medium
Swift 209 Minimum Size Subarray Sum Medium
Swift 208 Implement Trie (Prefix Tree) Medium
Swift 207 Course Schedule Medium
Swift 206 Reverse Linked List Easy
Swift 205 Isomorphic Strings Easy
Swift 204 Count Primes Easy
Swift 203 Remove Linked List Elements Easy
Swift 202 Happy Number Easy
201 Bitwise AND of Numbers Range Medium
Swift 200 Number of Islands Medium
Swift 199 Binary Tree Right Side View Medium
Swift 198 House Robber Easy
191 Number of 1 Bits Easy
190 Reverse Bits Easy
Swift 189 Rotate Array Easy
Swift 188 Best Time to Buy and Sell Stock IV Hard
187 Repeated DNA Sequences Medium
Swift 186 Reverse Words in a String II
Medium
Swift 179 Largest Number Medium
174 Dungeon Game Hard
Swift 173 Binary Search Tree Iterator Medium
Swift 172 Factorial Trailing Zeroes Easy
Swift 171 Excel Sheet Column Number Easy
Swift 170 Two Sum III – Data structure design
Easy
Swift 169 Majority Element Easy
168 Excel Sheet Column Title Easy
Swift 167 Two Sum II – Input array is sorted
Medium
Swift 166 Fraction to Recurring Decimal Medium
165 Compare Version Numbers Easy
164 Maximum Gap Hard
Swift 163 Missing Ranges
Medium
Swift 162 Find Peak Element Medium
Swift 161 One Edit Distance
Medium
160 Intersection of Two Linked Lists Easy
Swift 159 Longest Substring with At Most Two Distinct Characters
Hard
158 Read N Characters Given Read4 II – Call multiple times
Hard
157 Read N Characters Given Read4
Easy
Swift 156 Binary Tree Upside Down
Medium
Swift 155 Min Stack Easy
Swift 154 Find Minimum in Rotated Sorted Array II Hard
Swift 153 Find Minimum in Rotated Sorted Array Medium
Swift 152 Maximum Product Subarray Medium
Swift 151 Reverse Words in a String Medium
Swift 150 Evaluate Reverse Polish Notation Medium
149 Max Points on a Line Hard
148 Sort List Medium
147 Insertion Sort List Medium
Swift 146 LRU Cache Hard
Swift 145 Binary Tree Postorder Traversal Hard
Swift 144 Binary Tree Preorder Traversal Medium
Swift 143 Reorder List Medium
142 Linked List Cycle II Medium
141 Linked List Cycle Easy
140 Word Break II Hard
139 Word Break Medium
138 Copy List with Random Pointer Hard
Swift 137 Single Number II Medium
Swift 136 Single Number Medium
135 Candy Hard
Swift 134 Gas Station Medium
133 Clone Graph Medium
132 Palindrome Partitioning II Hard
Swift 131 Palindrome Partitioning Medium
130 Surrounded Regions Medium
129 Sum Root to Leaf Numbers Medium
Swift 128 Longest Consecutive Sequence Hard
Swift 127 Word Ladder Medium
126 Word Ladder II Hard
Swift 125 Valid Palindrome Easy
Swift 124 Binary Tree Maximum Path Sum Hard
Swift 123 Best Time to Buy and Sell Stock III Hard
Swift 122 Best Time to Buy and Sell Stock II Medium
Swift 121 Best Time to Buy and Sell Stock Easy
Swift 120 Triangle Medium
119 Pascal’s Triangle II Easy
118 Pascal’s Triangle Easy
117 Populating Next Right Pointers in Each Node II Hard
116 Populating Next Right Pointers in Each Node Medium
115 Distinct Subsequences Hard
Swift 114 Flatten Binary Tree to Linked List Medium
Swift 113 Path Sum II Medium
Swift 112 Path Sum Easy
Swift 111 Minimum Depth of Binary Tree Easy
Swift 110 Balanced Binary Tree Easy
109 Convert Sorted List to Binary Search Tree Medium
Swift 108 Convert Sorted Array to Binary Search Tree Medium
Swift 107 Binary Tree Level Order Traversal II Easy
Swift 106 Construct Binary Tree from Inorder and Postorder Traversal Medium
Swift 105 Construct Binary Tree from Preorder and Inorder Traversal Medium
Swift 104 Maximum Depth of Binary Tree Easy
Swift 103 Binary Tree Zigzag Level Order Traversal Medium
Swift 102 Binary Tree Level Order Traversal Easy
Swift 101 Symmetric Tree Easy
Swift 100 Same Tree Easy
Swift 99 Recover Binary Search Tree Hard
Swift 98 Validate Binary Search Tree Medium
97 Interleaving String Hard
Swift 96 Unique Binary Search Trees Medium
95 Unique Binary Search Trees II Medium
Swift 94 Binary Tree Inorder Traversal Medium
93 Restore IP Addresses Medium
92 Reverse Linked List II Medium
Swift 91 Decode Ways Medium
Swift 90 Subsets II Medium
Swift 89 Gray Code Medium
Swift 88 Merge Sorted Array Easy
87 Scramble String Hard
Swift 86 Partition List Medium
85 Maximal Rectangle Hard
84 Largest Rectangle in Histogram Hard
Swift 83 Remove Duplicates from Sorted List Easy
Swift 82 Remove Duplicates from Sorted List II Medium
Swift 81 Search in Rotated Sorted Array II Medium
Swift 80 Remove Duplicates from Sorted Array II Medium
Swift 79 Word Search Medium
Swfit 78 Subsets Medium
Swift 77 Combinations Medium
Swift 76 Minimum Window Substring Hard
Swift 75 Sort Colors Medium
Swift 74 Search a 2D Matrix Medium
Swift 73 Set Matrix Zeroes Medium
Swift 72 Edit Distance Hard
Swift 71 Simplify Path Medium
Swift 70 Climbing Stairs Easy
Swift 69 Sqrt(x) Medium
Swift 68 Text Justification Hard
Swift 67 Add Binary Easy
Swift 66 Plus One Easy
Swift 65 Valid Number Hard
Swift 64 Minimum Path Sum Medium
Swift 63 Unique Paths II Medium
Swift 62 Unique Paths Medium
Swift 61 Rotate List Medium
Swift 60 Permutation Sequence Medium
Swift 59 Spiral Matrix II Medium
Swift 58 Length of Last Word Easy
Swift 57 Insert Interval Hard
Swift 56 Merge Intervals Hard
Swift 55 Jump Game Medium
Swift 54 Spiral Matrix Medium
Swift 53 Maximum Subarray Medium
Swift 52 N-Queens II Hard
Swift 51 N-Queens Hard
Swift 50 “Pow(x, n)” Medium
Swift 49 Group Anagrams Medium
Swift 48 Rotate Image Medium
Swift 47 Permutations II Medium
Swift 46 Permutations Medium
45 Jump Game II Hard
Swift 44 Wildcard Matching Hard
Swift 43 Multiply Strings Medium
Swift 42 Trapping Rain Water Hard
Swift 41 First Missing Positive Hard
Swift 40 Combination Sum II Medium
Swift 39 Combination Sum Medium
Swift 38 Count and Say Easy
Swift 37 Sudoku Solver Hard
Swift 36 Valid Sudoku Easy
Swift 35 Search Insert Position Medium
Swift 34 Search for a Range Medium
Swift 33 Search in Rotated Sorted Array Hard
Swift 32 Longest Valid Parentheses Hard
Swift 31 Next Permutation Medium
30 Substring with Concatenation of All Words Hard
Swift 29 Divide Two Integers Medium
Swift 28 Implement strStr() Easy
Swfit 27 Remove Element Easy
Swift 26 Remove Duplicates from Sorted Array Easy
25 Reverse Nodes in k-Group Hard
Swift 24 Swap Nodes in Pairs Easy
Swift 23 Merge k Sorted Lists Hard
Swift 22 Generate Parentheses Medium
Swift 21 Merge Two Sorted Lists Easy
Swift 20 Valid Parentheses Easy
Swift 19 Remove Nth Node From End of List Easy
Swift 18 4Sum Medium
Swift 17 Letter Combinations of a Phone Number Medium
Swift 16 3Sum Closest Medium
Swift 15 3Sum Medium
Swift 14 Longest Common Prefix Easy
Swift 13 Roman to Integer Easy
Swift 12 Integer to Roman Medium
Swift 11 Container With Most Water Medium
Swift 10 Regular Expression Matching Hard
Swift 9 Palindrome Number Easy
Swift 8 String to Integer (atoi) Easy
Swift 7 Reverse Integer Easy
Swift 6 ZigZag Conversion Easy
Swift 5 Longest Palindromic Substring Medium
Swift 4 Median of Two Sorted Arrays Hard
Swift 3 Longest Substring Without Repeating Characters Medium
Swift 2 Add Two Numbers Medium
Swift 1 Two Sum Easy

GitHub

https://github.com/soapyigu/LeetCode-Swift