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