Before you start: Why do interviewers care so much about algorithm and data structure?
####LeetCode Solutions in Swift 2.1
- Designed for your next iOS job interview.
- Optimal solutions handpicked from the LeetCode community.
- Best time/space complexity guaranteed.
- Written with the latest Swift 2.1 language features in mind.
- Comprehensive test cases guarding against wrong answers and timeouts.
- A work in progress. Currently at 92 / ( 298 - 44 Paid Subscription ) = 36.2%, with 553 test cases.
#####Requires Xcode 7.2 Beta (Build 7C46l). Requires 64-bit simulators or devices to run test cases.
- Two Sum - Medium - Swift Solution - ObjC Solution - Test Cases - t=O(N), s=O(N) - Inspired by @naveed.zafar
- Add Two Numbers - Medium - Swift Solution - ObjC Solution - Test Cases - t=O(N), s=O(1) - Inspired by @potpie
- Longest Substring Without Repeating Characters - Medium - Swift Solution - ObjC Solution - Test Cases - t=O(N), s=O(1) - Inspired by @heiyanbin
- Median of Two Sorted Arrays - Hard - Swift Solution - ObjC Solution - Test Cases - t=O(log(min(m,n))), s=O(1) - Inspired by @MissMary - Be sure to read @MissMary's full explanation on how she achieved logarithmic time complexity with a few nice mathematic tricks.
- Longest Palindromic Substring - Medium - Swift Solution - ObjC Solution - Test Cases - t=O(N^2), s=O(1) - Inspired by @hh1985
- ZigZag Conversion - Easy - Solution - Test Cases - t=O(N), s=O(N) - Inspired by @dylan_yu
- Reverse Integer - Easy - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @wshaoxuan
- String to Integer (atoi) - Easy - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @yuruofeifei
- Palindrome Number - Easy - Solution - Test Cases, t=O(N), s=O(1) - Inspired by @hln9319
- Regular Expression Matching - Hard - Solution - Test Cases - DP, t=O(M*N), s=O(M*N) - Inspired by @xiaohui7
- Container With Most Water - Medium - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @franticguy
- Integer To Roman - Medium - Solution - Test Cases - t=O(1), s=O(1) - Inspired by @flytosky
- Roman To Integer - Easy - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @makeittrue
- Longest Common Prefix - Easy - Solution - Test Cases - t=O(N*M), s=O(1) - Inspired by @garysui
- 3Sum - Medium - Solution - Test Cases - t=O(N^2), s=O(N) - Inspired by @peerlessbloom
- 3Sum Closest - Medium - Solution - Test Cases - t=O(N^2), s=O(N)
- Letter Combinations of A Phone Number - Medium - Solution - Test Cases - t=(3^N), s=O(3^N)
- 4Sum - Medium - Solution - Test Cases - t=O(N^3), s=O(N)
- Remove Nth Node From End of List - Easy - Solution - Test Cases - t=O(N), s=O(1)
- Valid Parentheses - Easy - Solution - Test Cases - t=O(N), s=O(N)
- Merge Two Sorted Lists - Easy - Solution - Test Cases - t=O(max(M,N)), s=O(1)
- Generate Parentheses - Medium - Solution - Test Cases - t=O(N^2), s=O(N^2)
- Merge K Sorted Lists - Hard - Solution - Test Cases - t=O(N*logK), s=O(logK), where where N is the total number of elements, K is the number of lists
- Swap Nodes in Pairs - Medium - Solution - Test Cases, t=O(N), s=O(1)
- Reverse Nodes in k-Group - Hard - Solution - Test Cases - t=O(N), s=O(1)
- Remove Duplicates from Sorted Array - Easy - Solution - Test Cases - t=O(N), s=O(1)
- Remove Element- Easy - Solution - Test Cases - t=O(N), s=O(1)
- Implement strStr() - Easy - Solution - Test Cases - KMP: t=O(M+N), s=O(N). Brute-force: t=O(M*N), s=O(1).
- Divide Two Integers - Medium - Solution - Test Cases - t=O((logN)^2), s=O(1)
- Substring with Concatenation of All Words - Hard - Solution - Test Cases - t=O(N*W), s=O(L*W), where N is the length of the string, W is the length of a word, L is the length of the words list.
- Next Permutation - Medium - Solution - Test Cases - t=O(N), s=O(1)
- Longest Valid Parentheses - Hard - Solution - Test Cases - One pass, t=O(N), s=O(N)
- Search in Rotated Sorted Array - Hard - Solution - Test Cases - t=O(logN), s=O(1)
- Search for a Range - Medium - Solution - Test Cases - t=O(logN), s=O(1)
- Search Insert Position - Medium - Solution - Test Cases - t=O(logN), s=O(1)
- Valid Sudoku - Medium - Solution - Test Cases - t=O(1), s=O(1)
- Sudoku Solver - Hard - Solution - Test Cases - DFS
- Count and Say - Easy - Solution - Test Cases - t=(2^N), s=O(2^N)
- Combination Sum - Medium - Solution - Test Cases - t=O(N*M), s=O(M), where N is the length of the candidates array, M is the value of the target integer.
- Combination Sum II - Medium - Solution - Test Cases - t=O(N*M), s=O(M), where N is the length of the candidates array, M is the value of the target integer.
- First Missing Positive - Hard - Solution - Test Cases - t=O(N), s=O(1)
- Trapping Rain Water - Hard - Solution - Test Cases - t=O(N), s=O(1)
- Multiply Strings - Medium - Solution - Test Cases - t=O(N*M), s=O(N+M)
- Wildcard Matching - Hard - Solution - Test Cases - t=O(N), s=O(1)
- Jump Game II - Hard - Solution - Test Cases - t=O(N), s=O(1)
- Permutations - Medium - Solution - Test Cases - t=O(N!), s=O(N!)
- Permutations II - Hard - Solution - Test Cases - t=O(N!), s=O(N!)
- Rotate Image - Medium - Solution - Test Cases - t=O(N*N), s=O(1)
- Anagrams - Medium - Solution - Test Cases - t=O(N), s=O(N)
- Pow(x, n) - Medium - Solution - Test Cases - t=O(logN), s=O(logN)
- N-Queens - Hard - Solution - Test Cases - t=O(N^2), s=O(N^2)
- N-Queens II - Hard - Solution - Test Cases - t= well it's complicated...
- Maximum Subarray - Medium - Solution - Test Cases - t=O(N), s=O(1)
- Spiral Matrix - Medium - Solution - Test Cases - t=O(N), s=O(N)
- Jump Game - Medium - Solution - Test Cases - t=O(N), s=O(1)
- Merge Intervals - Hard - Solution - Test Cases - t=O(N*logN), s=O(N)
- Insert Interval - Hard - Solution - Test Cases - t=O(N), s=O(N)
- Length of Last Word - Easy - Solution - Test Cases - t=O(N), s=O(1)
- Spiral Matrix II - Medium - Solution - Test Cases - t=O(N^2), s=O(N^2)
- Permutation Sequence - Medium - Solution - Test Cases - t=O(N^2), s=O(N)
- Rotate List - Medium - Solution - Test Cases - t=O(N), s=O(1)
- Unique Paths - Medium - Solution - Test Cases - t=O(min(M, N)), s=O(1)
- Unique Paths II - Medium - Solution - Test Cases - t=O(M*N), s=O(1)
- Minimum Path Sum - Medium - Solution - Test Cases - t=O(M*N), s=O(1)
- Valid Number - Hard - Solution - Test Cases - t=O(N), s=O(1)
- Plus One - Easy - Solution - Test Cases - t=O(N), s=O(1)
- Add Binary - Easy - Solution - Test Cases - t=O(max(M,N)), s=O(max(M,N))
- Text Justification - Hard - Solution - Test Cases - t<=O(N*L), s<=O(N*L), where N is the length of the input words array, L is the required justified length
- Sqrt(x) - Medium - Solution - Test Cases - t=O(logN), s=O(1)
- Climbing Stairs - Easy - Solution - Test Cases - t=O(N), s=O(1)
- Simplify Path - Medium - Solution - Test Cases - t=O(N), s=O(N)
- Edit Distance - Hard - Solution - Test Cases - t=O(M*N), s=O(min(M,N))
- Set Matrix Zeroes - Medium - Solution - Test Cases - t=O(M*N), s=O(1)
- Search a 2D Matrix - Medium - Solution - Test Cases - t=O(logN), s=O(1)
- Sort Colors - Medium - Solution - Test Cases - t=O(N), s=O(1), one pass
- Minimum Window Substring - Hard - Solution - Test Cases - t=O(N), s=O(N)
- Combinations - Medium - Solution - Test Cases - t=O(Combination(n, k)+2^(k-1)), s is complicated.
- Subsets - Medium - Solution - Test Cases - t=O(N*2^N), s=O(n*2^N)
- Word Search - Medium - Solution - Test Cases - t=O(M*N*L), s=O(L), where L is the length of the word.
- Remove Duplicates from Sorted Array II - Medium - Solution - Test Cases - t=O(N), s=O(1)
- Search in Rotated Sorted Array II - Medium - Solution - Test Cases - average t=O(logN), worst case t=O(N), s=O(1)
- Remove Duplicates from Sorted List II - Medium - Solution - Test Cases - t=O(N), s=O(1)
- Remove Duplicates from Sorted List - Easy - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @Tao2014
- Largest Rectangle in Histogram - Hard - Solution - Test Cases - t=O(N), s=O(N) - Inspired by geeksforgeeks
- Maximal Rectangle - Hard - Solution - Test Cases - t=O(M*N), s=O(min(M,N)) - Inspired by @morrischen2008
- Partition List - Medium - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @shichaotan
- Scramble String - Hard - Solution - Test Cases - time and space complexity need further investigation - Inspired by @Charles_p and @dtx0
- Merge Sorted Array - Easy - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @leetchunhui
- Gray Code - Medium - Solution - Test Cases - t=O(2^N), s=O(2^N) - Inspired by @mike3
- Subsets II - Medium - Solution - Test Cases - t=O(2^N), s=O(2^N) - Inspired by @mathsam
- Decode Ways - Medium - Solution - Test Cases - t=O(N), s=O(N) - Inspired by @manky
- Reverse Linked List II - Medium - Swift Solution - ObjC Solution - Test Cases - t=O(N), s=O(1), One Pass - Inspired by @ardyadipta
Optional chaining, closure, subscript, enumeration, generic, extension, access control, automatic reference counting, string, character, nested type, type casting, protocol, xctestcase, xctest, online judge, oj, xcode, cocoa, cocoa touch, foundation, ios, 面试, 算法, 递归, 迭代, 找工作, 手机, 苹果, wwdc, POJ, PKU Online Judge, OJ, data structure, algorithm, algorithms, data structures, 数据结构, 算法与数据结构, interview, interviews, interviewer, interviewers, facebook, google, linkedin, apple, flag, cracking the coding interview, job, recruit, recruiter, recruiting.