Skip to content

About

LeetCode solutions in Swift with data structures, patterns, and step-by-step explanations

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCode Study Guide - Swift

Study guide for LeetCode using Swift. Includes data structure implementations, pattern explanations, and classic solved problems.

How to Study

  1. Read the data structure in DataStructures/ to understand the implementation
  2. Read the pattern in Patterns/ to understand the solving technique
  3. Solve the problem before looking at the solution in Problems/
  4. Compare your solution with the guide and analyze complexity

Roadmap

Phase Topic Data Structure Problems Status
1 Arrays & Hashing Array, Dictionary, Set Two Sum, Contains Duplicate, Group Anagrams, Top K Frequent
2 Two Pointers Array Valid Palindrome, Two Sum II, 3Sum, Container With Most Water
3 Sliding Window Array, Dictionary Best Time to Buy/Sell Stock, Longest Substring Without Repeating
4 Stack Stack Valid Parentheses, Min Stack, Daily Temperatures, Evaluate RPN
5 Binary Search Array Binary Search, Search Rotated Array, Find Min Rotated
6 Linked List LinkedList Reverse Linked List, Merge Two Lists, Linked List Cycle, Reorder List
7 Trees BinaryTree Invert Tree, Max Depth, Same Tree, Level Order, Validate BST
8 Heap / Priority Queue Heap Kth Largest Element, Last Stone Weight, K Closest Points
9 Graphs Graph Number of Islands, Clone Graph, Course Schedule, Pacific Atlantic
10 Dynamic Programming -- Climbing Stairs, Coin Change, Longest Common Subsequence, House Robber
11 Backtracking -- Subsets, Permutations, Combination Sum, N-Queens
12 Greedy -- Jump Game, Merge Intervals, Gas Station

Complexity - Cheat Sheet

Notation Name Example
O(1) Constant Array access by index
O(log n) Logarithmic Binary search
O(n) Linear Simple loop
O(n log n) Linearithmic Optimal sorting (merge sort)
O(n^2) Quadratic Nested double loop
O(2^n) Exponential Subsets, backtracking
O(n!) Factorial Permutations

Problem Template

// MARK: - Problem
// Link: https://leetcode.com/problems/...
// Difficulty: Easy/Medium/Hard

// MARK: - Approach
// Explanation of the strategy

// MARK: - Complexity
// Time: O(...)
// Space: O(...)

// MARK: - Solution
func solution(...) -> ... { }

// MARK: - Tests
assert(solution(...) == expected)

How to Run

Each .swift file can be run directly:

swift Problems/01-ArraysAndHashing/TwoSum.swift

Run All Tests

./run_tests.sh

About

LeetCode solutions in Swift with data structures, patterns, and step-by-step explanations

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages