Solutions to LeetCode problems written in Swift.
- Xcode 15.2+
- Swift 5.9
Each solution has test cases that can be found in the SolutionsTests folder.
I try to write tests covering as much of the code as possible (on top of the test cases provided by LeetCode).
You can modify the test cases, and provide new inputs and expected outputs.
Here's the representation of the project structure, to make it easier to navigate through all the content.
Please pay attention to this if adding problems and implementing solutions, so everything conforms to this folder structure.
.
├── LeetSwift # Companion app
│  └── ... # Project files
├── LeetSwift.xcworkspace
├── Package.swift # LeetSwift package spec
├── Sources
│  ├── Core # Data structures, helpers, etc.
│ │  └── ...
│  ├── Solutions
│  │ ├── ...
│  │ └── XXX - Problem title
│  │  ├── ProblemXXXDefinition.swift # Problem definition
│  │ ├── ProblemXXX<M>Solution.swift # Solution M
│  │ ├── ProblemXXX<N>Solution.swift # Solution N
│  │ ├── ... # Other solutions
│  │ └── README.md # Documentation and solutions
│ └── TestSupport # Supporting classes / extensions
│ ├── Array+ListNode.swift
│ ├── TestCaseProviding.swift
│ └── TestData.swift
└── Tests
├── CoreTests
│  └── ...
├── SolutionsTests
│ ├── ProblemXXXTests.swift # Test all solutions for Problem XXX
│ └── ... # Other tests
└── TestSupportTests
└── Utils
└── ... # Test support classes
Below, you can find a table with all the problems with their corresponding solution. You can find a detailed walkthrough of the solutions to these problems on my blog jobear.dev.
A
: ArrayHT
: Hash TableLL
: Linked ListM
: MathR
: RecursionS
: StringSW
: Sliding WindowBS
: Binary SearchDC
: Divide and ConquerTP
: Two PointersDP
: Dynamic ProgrammingG
: GreedyT
: TrieSO
: SortingBT
: BacktrackingST
: StackH
: HeapMS
: Merge SortSM
: String MatchingBM
: Bit Manipulation
Here, I use the TDD approach, writing the test cases before writing the solution. This way, I can quickly verify if the solution works as expected.
The goal is always to have enough test cases for all the problems and then work on the solution until all of these test cases are green.
If you would like to contribute, please use this same approach.
Please note this project uses the GNU AGPLv3 license, which requires any code or software that uses it to make their code completely available.
This project is intended to be used for educational purposes only.
Please acknowledge the license and contact me if you intend to use any content from here.