Coder Social home page Coder Social logo

sarstw / leetcode-solutions-in-swift Goto Github PK

View Code? Open in Web Editor NEW

This project forked from diwu/leetcode-solutions-in-swift

0.0 2.0 0.0 662 KB

Get prepared for your next iOS job interview by studying high quality LeetCode solutions in Swift 2.1.

License: MIT License

Objective-C 3.10% Swift 96.90%

leetcode-solutions-in-swift's Introduction

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.

  1. Two Sum - Medium - Swift Solution - ObjC Solution - Test Cases - t=O(N), s=O(N) - Inspired by @naveed.zafar
  2. Add Two Numbers - Medium - Swift Solution - ObjC Solution - Test Cases - t=O(N), s=O(1) - Inspired by @potpie
  3. Longest Substring Without Repeating Characters - Medium - Swift Solution - ObjC Solution - Test Cases - t=O(N), s=O(1) - Inspired by @heiyanbin
  4. 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.
  5. Longest Palindromic Substring - Medium - Swift Solution - ObjC Solution - Test Cases - t=O(N^2), s=O(1) - Inspired by @hh1985
  6. ZigZag Conversion - Easy - Solution - Test Cases - t=O(N), s=O(N) - Inspired by @dylan_yu
  7. Reverse Integer - Easy - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @wshaoxuan
  8. String to Integer (atoi) - Easy - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @yuruofeifei
  9. Palindrome Number - Easy - Solution - Test Cases, t=O(N), s=O(1) - Inspired by @hln9319
  10. Regular Expression Matching - Hard - Solution - Test Cases - DP, t=O(M*N), s=O(M*N) - Inspired by @xiaohui7
  11. Container With Most Water - Medium - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @franticguy
  12. Integer To Roman - Medium - Solution - Test Cases - t=O(1), s=O(1) - Inspired by @flytosky
  13. Roman To Integer - Easy - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @makeittrue
  14. Longest Common Prefix - Easy - Solution - Test Cases - t=O(N*M), s=O(1) - Inspired by @garysui
  15. 3Sum - Medium - Solution - Test Cases - t=O(N^2), s=O(N) - Inspired by @peerlessbloom
  16. 3Sum Closest - Medium - Solution - Test Cases - t=O(N^2), s=O(N)
  17. Letter Combinations of A Phone Number - Medium - Solution - Test Cases - t=(3^N), s=O(3^N)
  18. 4Sum - Medium - Solution - Test Cases - t=O(N^3), s=O(N)
  19. Remove Nth Node From End of List - Easy - Solution - Test Cases - t=O(N), s=O(1)
  20. Valid Parentheses - Easy - Solution - Test Cases - t=O(N), s=O(N)
  21. Merge Two Sorted Lists - Easy - Solution - Test Cases - t=O(max(M,N)), s=O(1)
  22. Generate Parentheses - Medium - Solution - Test Cases - t=O(N^2), s=O(N^2)
  23. 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
  24. Swap Nodes in Pairs - Medium - Solution - Test Cases, t=O(N), s=O(1)
  25. Reverse Nodes in k-Group - Hard - Solution - Test Cases - t=O(N), s=O(1)
  26. Remove Duplicates from Sorted Array - Easy - Solution - Test Cases - t=O(N), s=O(1)
  27. Remove Element- Easy - Solution - Test Cases - t=O(N), s=O(1)
  28. Implement strStr() - Easy - Solution - Test Cases - KMP: t=O(M+N), s=O(N). Brute-force: t=O(M*N), s=O(1).
  29. Divide Two Integers - Medium - Solution - Test Cases - t=O((logN)^2), s=O(1)
  30. 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.
  31. Next Permutation - Medium - Solution - Test Cases - t=O(N), s=O(1)
  32. Longest Valid Parentheses - Hard - Solution - Test Cases - One pass, t=O(N), s=O(N)
  33. Search in Rotated Sorted Array - Hard - Solution - Test Cases - t=O(logN), s=O(1)
  34. Search for a Range - Medium - Solution - Test Cases - t=O(logN), s=O(1)
  35. Search Insert Position - Medium - Solution - Test Cases - t=O(logN), s=O(1)
  36. Valid Sudoku - Medium - Solution - Test Cases - t=O(1), s=O(1)
  37. Sudoku Solver - Hard - Solution - Test Cases - DFS
  38. Count and Say - Easy - Solution - Test Cases - t=(2^N), s=O(2^N)
  39. 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.
  40. 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.
  41. First Missing Positive - Hard - Solution - Test Cases - t=O(N), s=O(1)
  42. Trapping Rain Water - Hard - Solution - Test Cases - t=O(N), s=O(1)
  43. Multiply Strings - Medium - Solution - Test Cases - t=O(N*M), s=O(N+M)
  44. Wildcard Matching - Hard - Solution - Test Cases - t=O(N), s=O(1)
  45. Jump Game II - Hard - Solution - Test Cases - t=O(N), s=O(1)
  46. Permutations - Medium - Solution - Test Cases - t=O(N!), s=O(N!)
  47. Permutations II - Hard - Solution - Test Cases - t=O(N!), s=O(N!)
  48. Rotate Image - Medium - Solution - Test Cases - t=O(N*N), s=O(1)
  49. Anagrams - Medium - Solution - Test Cases - t=O(N), s=O(N)
  50. Pow(x, n) - Medium - Solution - Test Cases - t=O(logN), s=O(logN)
  51. N-Queens - Hard - Solution - Test Cases - t=O(N^2), s=O(N^2)
  52. N-Queens II - Hard - Solution - Test Cases - t= well it's complicated...
  53. Maximum Subarray - Medium - Solution - Test Cases - t=O(N), s=O(1)
  54. Spiral Matrix - Medium - Solution - Test Cases - t=O(N), s=O(N)
  55. Jump Game - Medium - Solution - Test Cases - t=O(N), s=O(1)
  56. Merge Intervals - Hard - Solution - Test Cases - t=O(N*logN), s=O(N)
  57. Insert Interval - Hard - Solution - Test Cases - t=O(N), s=O(N)
  58. Length of Last Word - Easy - Solution - Test Cases - t=O(N), s=O(1)
  59. Spiral Matrix II - Medium - Solution - Test Cases - t=O(N^2), s=O(N^2)
  60. Permutation Sequence - Medium - Solution - Test Cases - t=O(N^2), s=O(N)
  61. Rotate List - Medium - Solution - Test Cases - t=O(N), s=O(1)
  62. Unique Paths - Medium - Solution - Test Cases - t=O(min(M, N)), s=O(1)
  63. Unique Paths II - Medium - Solution - Test Cases - t=O(M*N), s=O(1)
  64. Minimum Path Sum - Medium - Solution - Test Cases - t=O(M*N), s=O(1)
  65. Valid Number - Hard - Solution - Test Cases - t=O(N), s=O(1)
  66. Plus One - Easy - Solution - Test Cases - t=O(N), s=O(1)
  67. Add Binary - Easy - Solution - Test Cases - t=O(max(M,N)), s=O(max(M,N))
  68. 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
  69. Sqrt(x) - Medium - Solution - Test Cases - t=O(logN), s=O(1)
  70. Climbing Stairs - Easy - Solution - Test Cases - t=O(N), s=O(1)
  71. Simplify Path - Medium - Solution - Test Cases - t=O(N), s=O(N)
  72. Edit Distance - Hard - Solution - Test Cases - t=O(M*N), s=O(min(M,N))
  73. Set Matrix Zeroes - Medium - Solution - Test Cases - t=O(M*N), s=O(1)
  74. Search a 2D Matrix - Medium - Solution - Test Cases - t=O(logN), s=O(1)
  75. Sort Colors - Medium - Solution - Test Cases - t=O(N), s=O(1), one pass
  76. Minimum Window Substring - Hard - Solution - Test Cases - t=O(N), s=O(N)
  77. Combinations - Medium - Solution - Test Cases - t=O(Combination(n, k)+2^(k-1)), s is complicated.
  78. Subsets - Medium - Solution - Test Cases - t=O(N*2^N), s=O(n*2^N)
  79. Word Search - Medium - Solution - Test Cases - t=O(M*N*L), s=O(L), where L is the length of the word.
  80. Remove Duplicates from Sorted Array II - Medium - Solution - Test Cases - t=O(N), s=O(1)
  81. Search in Rotated Sorted Array II - Medium - Solution - Test Cases - average t=O(logN), worst case t=O(N), s=O(1)
  82. Remove Duplicates from Sorted List II - Medium - Solution - Test Cases - t=O(N), s=O(1)
  83. Remove Duplicates from Sorted List - Easy - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @Tao2014
  84. Largest Rectangle in Histogram - Hard - Solution - Test Cases - t=O(N), s=O(N) - Inspired by geeksforgeeks
  85. Maximal Rectangle - Hard - Solution - Test Cases - t=O(M*N), s=O(min(M,N)) - Inspired by @morrischen2008
  86. Partition List - Medium - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @shichaotan
  87. Scramble String - Hard - Solution - Test Cases - time and space complexity need further investigation - Inspired by @Charles_p and @dtx0
  88. Merge Sorted Array - Easy - Solution - Test Cases - t=O(N), s=O(1) - Inspired by @leetchunhui
  89. Gray Code - Medium - Solution - Test Cases - t=O(2^N), s=O(2^N) - Inspired by @mike3
  90. Subsets II - Medium - Solution - Test Cases - t=O(2^N), s=O(2^N) - Inspired by @mathsam
  91. Decode Ways - Medium - Solution - Test Cases - t=O(N), s=O(N) - Inspired by @manky
  92. 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.

leetcode-solutions-in-swift's People

Contributors

diwu avatar testpersonal avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.