愚者千虑,必有一得。
As an idiot of algorithms, I make bold to resolve the problems on LeetCode, especially, in Swift. Most of the algorithms were not figured out by myself.
PLEASE DO NOT CONTRIBUTE until I accomplish all of them.
let 😎 = "Easy", 😐 = "Medium", 😨 = "Hard", ㊙️ = "require premium membership"
- 1 😐 Two Sum .swift
- 2 😐 Add Two Numbers .swift
- 3 😐 Longest Substring Without Repeating Characters
- 4 😨 Median of Two Sorted Arrays
- 5 😐 Longest Palindromic Substring
- 6 😎 ZigZag Conversion .swift
- 7 😎 Reverse Integer .swift
- 8 😎 String to Integer (atoi) .swift
- 9 😎 Palindrome Number .swift
- 10 😨 Regular Expression Matching
- 11 😐 Container With Most Water
- 12 😐 Integer to Roman
- 13 😎 Roman to Integer .swift
- 14 😎 Longest Common Prefix .swift
- 15 😐 3Sum
- 16 😐 3Sum Closest
- 17 😐 Letter Combinations of a Phone Number
- 18 😐 4Sum
- 19 😎 Remove Nth Node From End of List .swift
- 20 😎 Valid Parentheses .swift
- 21 😎 Merge Two Sorted Lists .swift
- 22 😐 Generate Parentheses
- 23 😨 Merge k Sorted Lists
- 24 😐 Swap Nodes in Pairs
- 25 😨 Reverse Nodes in k-Group
- 26 😎 Remove Duplicates from Sorted Array .swift
- 27 😎 Remove Element .swift
- 28 😎 Implement strStr() .swift
- 29 😐 Divide Two Integers
- 30 😨 Substring with Concatenation of All Words
- 31 😐 Next Permutation
- 32 😨 Longest Valid Parentheses
- 33 😨 Search in Rotated Sorted Array
- 34 😐 Search for a Range
- 35 😐 Search Insert Position
- 36 😎 Valid Sudoku
- 37 😨 Sudoku Solver
- 38 😎 Count and Say .swift
- 39 😐 Combination Sum
- 40 😐 Combination Sum II
- 41 😨 First Missing Positive
- 42 😨 Trapping Rain Water
- 43 😐 Multiply Strings
- 44 😨 Wildcard Matching
- 45 😨 Jump Game II
- 46 😐 Permutations
- 47 😐 Permutations II
- 48 😐 Rotate Image
- 49 😐 Group Anagrams .swift
- 50 😐 Pow(x, n)
- 51 😨 N-Queens
- 52 😨 N-Queens II
- 53 😐 Maximum Subarray
- 54 😐 Spiral Matrix
- 55 😐 Jump Game
- 56 😨 Merge Intervals
- 57 😨 Insert Interval
- 58 😎 Length of Last Word .swift
- 59 😐 Spiral Matrix II
- 60 😐 Permutation Sequence
- 61 😐 Rotate List
- 62 😐 Unique Paths
- 63 😐 Unique Paths II
- 64 😐 Minimum Path Sum
- 65 😨 Valid Number .swift
- 66 😎 Plus One .swift
- 67 😎 Add Binary .swift
- 68 😨 Text Justification
- 69 😐 Sqrt(x)
- 70 😎 Climbing Stairs
- 71 😐 Simplify Path
- 72 😨 Edit Distance
- 73 😐 Set Matrix Zeroes
- 74 😐 Search a 2D Matrix
- 75 😐 Sort Colors
- 76 😨 Minimum Window Substring
- 77 😐 Combinations
- 78 😐 Subsets
- 79 😐 Word Search
- 80 😐 Remove Duplicates from Sorted Array II
- 81 😐 Search in Rotated Sorted Array II
- 82 😐 Remove Duplicates from Sorted List II .swift
- 83 😎 Remove Duplicates from Sorted List .swift
- 84 😨 Largest Rectangle in Histogram
- 85 😨 Maximal Rectangle
- 86 😐 Partition List
- 87 😨 Scramble String
- 88 😎 Merge Sorted Array .swift
- 89 😐 Gray Code
- 90 😐 Subsets II
- 91 😐 Decode Ways
- 92 😐 Reverse Linked List II
- 93 😐 Restore IP Addresses
- 94 😐 Binary Tree Inorder Traversal
- 95 😐 Unique Binary Search Trees II
- 96 😐 Unique Binary Search Trees
- 97 😨 Interleaving String
- 98 😐 Validate Binary Search Tree
- 99 😨 Recover Binary Search Tree
- 100 😎 Same Tree .swift
- 101 😎 Symmetric Tree .swift
- 102 😎 Binary Tree Level Order Traversal
- 103 😐 Binary Tree Zigzag Level Order Traversal
- 104 😎 Maximum Depth of Binary Tree .swift
- 105 😐 Construct Binary Tree from Preorder and Inorder Traversal
- 106 😐 Construct Binary Tree from Inorder and Postorder Traversal
- 107 😎 Binary Tree Level Order Traversal II
- 108 😐 Convert Sorted Array to Binary Search Tree
- 109 😐 Convert Sorted List to Binary Search Tree
- 110 😎 Balanced Binary Tree .swift
- 111 😎 Minimum Depth of Binary Tree .swift
- 112 😎 Path Sum
- 113 😐 Path Sum II
- 114 😐 Flatten Binary Tree to Linked List .swift
- 115 😨 Distinct Subsequences
- 116 😐 Populating Next Right Pointers in Each Node
- 117 😨 Populating Next Right Pointers in Each Node II
- 118 😎 Pascal's Triangle
- 119 😎 Pascal's Triangle II
- 120 😐 Triangle
- 121 😐 Best Time to Buy and Sell Stock
- 122 😐 Best Time to Buy and Sell Stock II
- 123 😨 Best Time to Buy and Sell Stock III
- 124 😨 Binary Tree Maximum Path Sum
- 125 😎 Valid Palindrome
- 126 😨 Word Ladder II
- 127 😐 Word Ladder
- 128 😨 Longest Consecutive Sequence
- 129 😐 Sum Root to Leaf Numbers
- 130 😐 Surrounded Regions
- 131 😐 Palindrome Partitioning
- 132 😨 Palindrome Partitioning II
- 133 😐 Clone Graph
- 134 😐 Gas Station
- 135 😨 Candy
- 136 😐 Single Number
- 137 😐 Single Number II
- 138 😨 Copy List with Random Pointer
- 139 😐 Word Break
- 140 😨 Word Break II
- 141 😐 Linked List Cycle
- 142 😐 Linked List Cycle II
- 143 😐 Reorder List
- 144 😐 Binary Tree Preorder Traversal
- 145 😨 Binary Tree Postorder Traversal
- 146 😨 LRU Cache
- 147 😐 Insertion Sort List
- 148 😐 Sort List
- 149 😨 Max Points on a Line
- 150 😐 Evaluate Reverse Polish Notation
- 151 😐 Reverse Words in a String
- 152 😐 Maximum Product Subarray
- 153 😐 Find Minimum in Rotated Sorted Array
- 154 😨 Find Minimum in Rotated Sorted Array II
- 155 😎 Min Stack .swift
- 156 😐 Binary Tree Upside Down ㊙️
- 157 😎 Read N Characters Given Read4 ㊙️
- 158 😨 Read N Characters Given Read4 II - Call multiple times ㊙️
- 159 😨 Longest Substring with At Most Two Distinct Characters ㊙️
- 160 😎 Intersection of Two Linked Lists
- 161 😐 One Edit Distance ㊙️
- 162 😐 Find Peak Element
- 163 😐 Missing Ranges ㊙️
- 164 😨 Maximum Gap
- 165 😎 Compare Version Numbers .swift
- 166 😐 Fraction to Recurring Decimal
- 167 😐 Two Sum II - Input array is sorted ㊙️
- 168 😎 Excel Sheet Column Title
- 169 😎 Majority Element
- 170 😎 Two Sum III - Data structure design ㊙️
- 171 😎 Excel Sheet Column Number
- 172 😎 Factorial Trailing Zeroes
- 173 😐 Binary Search Tree Iterator
- 174 😨 Dungeon Game
- 179 😐 Largest Number
- 186 😐 Reverse Words in a String II ㊙️
- 187 😐 Repeated DNA Sequences
- 188 😨 Best Time to Buy and Sell Stock IV
- 189 😎 Rotate Array .swift
- 190 😎 Reverse Bits
- 191 😎 Number of 1 Bits
- 198 😎 House Robber
- 199 😐 Binary Tree Right Side View
- 200 😐 Number of Islands
- 201 😐 Bitwise AND of Numbers Range
- 202 😎 Happy Number
- 203 😎 Remove Linked List Elements
- 204 😎 Count Primes
- 205 😎 Isomorphic Strings
- 206 😎 Reverse Linked List
- 207 😐 Course Schedule
- 208 😐 Implement Trie (Prefix Tree)
- 209 😐 Minimum Size Subarray Sum
- 210 😐 Course Schedule II
- 211 😐 Add and Search Word - Data structure design
- 212 😨 Word Search II
- 213 😐 House Robber II
- 214 😨 Shortest Palindrome
- 215 😐 Kth Largest Element in an Array
- 216 😐 Combination Sum III
- 217 😎 Contains Duplicate
- 218 😨 The Skyline Problem
- 219 😎 Contains Duplicate II
- 220 😐 Contains Duplicate III
- 221 😐 Maximal Square
- 222 😐 Count Complete Tree Nodes
- 223 😎 Rectangle Area
- 224 😐 Basic Calculator
- 225 😎 Implement Stack using Queues
- 226 😎 Invert Binary Tree .swift
- 227 😐 Basic Calculator II
- 228 😎 Summary Ranges
- 229 😐 Majority Element II
- 230 😐 Kth Smallest Element in a BST
- 231 😎 Power of Two
- 232 😎 Implement Queue using Stacks
- 233 😐 Number of Digit One
- 234 😎 Palindrome Linked List
- 235 😎 Lowest Common Ancestor of a Binary Search Tree
- 236 😐 Lowest Common Ancestor of a Binary Tree
- 237 😎 Delete Node in a Linked List
- 238 😐 Product of Array Except Self
- 239 😨 Sliding Window Maximum
- 240 😐 Search a 2D Matrix II
- 241 😐 Different Ways to Add Parentheses
- 242 😎 Valid Anagram .swift
- 243 😎 Shortest Word Distance ㊙️
- 244 😐 Shortest Word Distance II ㊙️
- 245 😐 Shortest Word Distance III ㊙️
- 246 😎 Strobogrammatic Number ㊙️
- 247 😐 Strobogrammatic Number II ㊙️
- 248 😨 Strobogrammatic Number III ㊙️
- 249 😎 Group Shifted Strings ㊙️
- 250 😐 Count Univalue Subtrees ㊙️
- 251 😐 Flatten 2D Vector ㊙️
- 252 😎 Meeting Rooms ㊙️
- 253 😐 Meeting Rooms II ㊙️
- 254 😐 Factor Combinations ㊙️
- 255 😐 Verify Preorder Sequence in Binary Search Tree ㊙️
- 256 😐 Paint House ㊙️
- 257 😎 Binary Tree Paths
- 258 😎 Add Digits .swift
- 259 😐 3Sum Smaller ㊙️
- 260 😐 Single Number III
- 261 😐 Graph Valid Tree ㊙️
- 263 😎 Ugly Number .swift
- 264 😐 Ugly Number II
- 265 😨 Paint House II ㊙️
- 266 😎 Palindrome Permutation ㊙️
- 267 😐 Palindrome Permutation II ㊙️
- 268 😐 Missing Number
- 269 😨 Alien Dictionary ㊙️
- 270 😎 Closest Binary Search Tree Value ㊙️
- 271 😐 Encode and Decode Strings ㊙️
- 272 😨 Closest Binary Search Tree Value II ㊙️
- 273 😐 Integer to English Words
- 274 😐 H-Index
- 275 😐 H-Index II
- 276 😎 Paint Fence ㊙️
- 277 😐 Find the Celebrity ㊙️
- 278 😎 First Bad Version
- 279 😐 Perfect Squares
- 280 😐 Wiggle Sort ㊙️
- 281 😐 Zigzag Iterator ㊙️
- 282 😨 Expression Add Operators
- 283 😎 Move Zeroes .swift
- 284 😐 Peeking Iterator
- 285 😐 Inorder Successor in BST ㊙️
- 286 😐 Walls and Gates ㊙️
- 287 😨 Find the Duplicate Number
- 288 😎 Unique Word Abbreviation ㊙️
- 289 😐 Game of Life
- 290 😎 Word Pattern
- 291 😨 Word Pattern II ㊙️
- 292 😎 Nim Game
- 293 😎 Flip Game ㊙️
- 294 😐 Flip Game II ㊙️
- 295 😨 Find Median from Data Stream
- 296 😨 Best Meeting Point ㊙️
- 297 😐 Serialize and Deserialize Binary Tree
- 298 😐 Binary Tree Longest Consecutive Sequence ㊙️
- 299 😎 Bulls and Cows
- 300 😐 Longest Increasing Subsequence
- 301 😨 Remove Invalid Parentheses
- 302 😨 Smallest Rectangle Enclosing Black Pixels ㊙️
- 303 😎 Range Sum Query - Immutable
- 304 😐 Range Sum Query 2D - Immutable
- 305 😨 Number of Islands II ㊙️
- 306 😐 Additive Number
- 307 😐 Range Sum Query - Mutable
- 308 😨 Range Sum Query 2D - Mutable ㊙️
- 309 😐 Best Time to Buy and Sell Stock with Cooldown
- 310 😐 Minimum Height Trees
- 311 😐 Sparse Matrix Multiplication ㊙️
- 312 😨 Burst Balloons
- 313 😐 Super Ugly Number
- 314 😐 Binary Tree Vertical Order Traversal ㊙️
- 315 😨 Count of Smaller Numbers After Self
- 316 😐 Remove Duplicate Letters
- 317 😨 Shortest Distance from All Buildings ㊙️
- 318 😐 Maximum Product of Word Lengths
- 319 😐 Bulb Switcher
- 320 😐 Generalized Abbreviation ㊙️
- 321 😨 Create Maximum Number
- 322 😐 Coin Change
- 323 😐 Number of Connected Components in an Undirected Graph ㊙️
- 324 😐 Wiggle Sort II
- 325 😎 Maximum Size Subarray Sum Equals k ㊙️
- 326 😎 Power of Three .swift
- 327 😨 Count of Range Sum
Open the project with Xcode 7.2 then press ⌘ + u
.
Or run rake test
in this folder if you have xctool installed.
Copyright (C) 2016 lexrus.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.