Skip to content
Go to file


Failed to load latest commit information.
Latest commit message
Commit time


Solutions to LeetCode by Swift.

Tags Abbreviated description

  • A : Array
  • DP : Dynamic Programming
  • Str : String
  • M : Math
  • T : Tree
  • HT : Hash Table
  • DFS : Depth-first Search
  • BFS : Breadth-first Search
  • BS : Binary Search
  • TP : Two Pointers
  • B : Backtracking
  • LL : Linked List
  • D&C : Divide and Conquer
  • H : Heap
  • S : Sort
  • G : Greedy
  • BM : Bit Manipulation
  • St : Stack
  • Q : Queue
  • D : Design
  • GP : Graph

How to debug

The main.swift is to initialized Solution.func(val), then you can debug. Be sure when you initialize the Solution's swift file has chosen Target Membership, like the following image. And once time you just choose one Solution's swift file!

Solution Analysis

You can find all solution analysis in my blog LeetCode OJ, and the analysis to each problem is in the mext table blog.


# Title Solution Difficulty Tags Blog
1 Two Sum Solution A HT blog
2 Add Two Numbers Solution LL M blog
3 Longest Substring Without Repeating Characters Solution HT TP Str blog
4 Median of Two Sorted Arrays Solution A BS D&C -
12 Integer to Roman Solution M A blog
13 Roman to Integer Solution M A blog
14 Longest Common Prefix Solution Str blog
19 Remove Nth Node From End of List Solution LL TP blog
20 Valid Parentheses Solution St Str blog
21 Merge Two Sorted Lists Solution LL blog
26 Remove Duplicates from Sorted Array Solution A TP blog
27 Remove Element Solution A TP blog
28 Implement strStr() Solution TP Str blog
32 Longest Valid Parentheses Solution DP Str blog
35 Search Insert Position Solution A BS blog
44 Wildcard Matching Solution DP Str G B blog
50 Pow(x, n) Solution M BS blog
53 Maximum Subarray Solution A D&C DP blog
54 Spiral Matrix Solution A blog
61 Rotate List Solution LL TP blog
63 Unique Paths II Solution A DP blog
66 Plus One Solution A M blog
67 Add Binary Solution Str M blog
70 Climbing Stairs Solution DP blog
79 Word Search Solution A B blog
94 Binary Tree Inorder Traversal Solution HT St T blog
96 Unique Binary Search Trees Solution T DP blog
101 Symmetric Tree Solution T DFS BFS blog
102 Binary Tree Level Order Traversal Solution T BFS blog
104 Maximum Depth of Binary Tree Solution T DFS blog
105 Construct Binary Tree from Preorder and Inorder Traversal Solution T DFS A blog
106 Construct Binary Tree from Inorder and Postorder Traversal Solution T DFS A blog
108 Convert Sorted Array to Binary Search Tree Solution T DS blog
112 Path Sum Solution T DFS blog
113 Path Sum II Solution T DFS blog
116 Populating Next Right Pointers in Each Node Solution T DFS blog
117 Populating Next Right Pointers in Each Node II Solution T DFS blog
118 Pascal's Triangle Solution A blog
119 Pascal's Triangle II Solution A blog
120 Triangle Solution A DP blog
138 Copy List with Random Pointer Solution HT LL blog
139 Word Break Solution DP blog
140 Word Break II Solution DP B blog
141 Linked List Cycle Solution LL TP blog
142 Linked List Cycle II Solution LL TP blog
144 Binary Tree Preorder Traversal Solution St T blog
145 Binary Tree Postorder Traversal Solution St T blog
150 Evaluate Reverse Polish Notation Solution St blog
151 Reverse Words in a String Solution Str blog
153 Find Minimum in Rotated Sorted Array Solution A BS blog
154 Find Minimum in Rotated Sorted Array II Solution A BS blog
155 Min Stack Solution St D blog
160 Intersection of Two Linked Lists Solution LL blog
164 Maximum Gap Solution S blog
167 Two Sum II - Input array is sorted Solution A TP BS blog
189 Rotate Array Solution A blog
191 Number of 1 Bits Solution BM 题解
203 Remove Linked List Elements Solution LL blog
206 Reverse Linked List Solution LL blog
209 Minimum Size Subarray Sum Solution A TP BS blog
225 Implement Stack using Queues Solution St D blog
226 Invert Binary Tree Solution T blog
236 Lowest Common Ancestor of a Binary Tree Solution T blog
232 Implement Queue using Stacks Solution St D blog
234 Palindrome Linked List Solution LL TP blog
240 Search a 2D Matrix II Solution BS D&C blog
283 Move Zeroes Solution A TP blog
297 Serialize and Deserialize Binary Tree Solution T D blog
309 Best Time to Buy and Sell Stock with Cooldown Solution DP blog
328 Odd Even Linked List Solution LL blog
343 Integer Break Solution M DP blog
344 Reverse String Solution Str TP blog
346 Moving Average from Data Stream Solution Q blog
373 Find K Pairs with Smallest Sums Solution H blog
378 Kth Smallest Element in a Sorted Matrix Solution H BS blog
394 Decode String Solution St DFS blog
404 Sum of Left Leaves Solution T blog
449 Serialize and Deserialize BST Solution T blog
455 Assign Cookies Solution G blog
461 Hamming Distance Solution BM blog
485 Max Consecutive Ones Solution A blog
498 Diagonal Traverse Solution A blog
509 Fibonacci Number Solution A blog
557 Reverse Words in a String III Solution Str blog
561 Array Partition I Solution A blog
566 Reshape the Matrix Solution A blog
628 Maximum Product of Three Numbers Solution A M blog
657 Robot Return to Origin Solution Str blog
707 Design Linked List Solution M LL blog
718 Maximum Length of Repeated Subarray Solution A HT BS DP blog
724 Find Pivot Index Solution A blog
739 Daily Temperatures Solution St HT blog
747 Largest Number At Least Twice of Others Solution A blog
785 Is Graph Bipartite? Solution DFS BFS GP blog
946 Validate Stack Sequences Solution St blog


Solutions to LeetCode by Swift.





No releases published


No packages published


You can’t perform that action at this time.