- PHP >= 8.0
- PHPUnit >= 9.5
Install the package through Composer.
Run the Composer require command from the Terminal:
$ git clone git@github.com:imajinyun/leetcode-php.git
$ cd leetcode-php && composer install
$ phpunit -vvv
Array
HashTable
Subject | Source | Solution |
---|---|---|
0001. 两数之和 |
Two Sum | Solution |
0012. 整数转罗马数字 |
Integer to Roman | Solution |
0013. 罗马数字转整数 |
Roman to Integer | Solution |
0136. 只出现一次的数字 |
Single Number | Solution |
0202. 快乐数 |
Happy Number | Solution |
0242. 有效的字母异位词 |
Valid Anagram | Solution |
0349. 两个数组的交集 |
Intersection of Two Arrays | Solution |
0387. 字符串中的第一个唯一字符 |
First Unique Character in a String | Solution |
0454. 四数相加 II |
4Sum II | Solution |
Linked List
Subject | Source | Solution |
---|---|---|
0002. 两数相加 |
Add Two Numbers | Solution |
0021. 合并两个有序链表 |
Merge Two Sorted Lists | Solution |
0024. 两两交换链表中的节点 |
Swap Nodes in Pairs | Solution |
0092. 反转链表 II |
Reverse Linked List II | Solution |
0203. 移除链表元素 |
Remove Linked List Elements | Solution |
0206. 反转链表 |
Reverse Linked List | Solution |
0141. 环形链表 |
Linked List Cycle | Solution |
0234. 回文链表 |
Palindrome Linked List | Solution |
0237. 删除链表中的节点 |
Delete Node in a Linked List | Solution |
0707. 设计链表 |
Design Linked List | Solution |
Math
Subject | Source | Solution |
---|---|---|
0013. 罗马数字转整数 |
Roman to Integer | Solution |
0050. 计算 x 的 n 次幂 |
Pow(x, n) | Solution |
0066. 加一 |
Plus One | Solution |
0069. X 的平方根 |
Sqrt(x) | Solution |
0150. 逆波兰表达式求值 |
Evaluate Reverse Polish Notation | Solution |
0171. Excel 表列序号 |
Excel Sheet Column Number | Solution |
0227. 基本计算器 II |
Basic Calculator II | Solution |
1118. 一月有多少天 |
Number of Days in a Month | Solution |
Two Pointers
Subject | Source | Solution |
---|---|---|
0015. 三数之和 |
3Sum | Solution |
0016. 最接近的三数之和 |
3Sum Closest | Solution |
0018. 四数之和 |
4Sum | Solution |
0019. 删除链表的倒数第 N 个节点 |
Remove Nth Node From End of List | Solution |
0142. 环形链表 II |
Linked List Cycle II | Solution |
0209. 长度最小的子数组 |
Minimum Size Subarray Sum | Solution |
0287. 寻找重复数 |
Find the Duplicate Number | Solution |
0844. 比较含退格的字符串 |
Backspace String Compare | Solution |
0997. 有序数组的平方 |
Squares of a Sorted Array | Solution |
String
Subject | Source | Solution |
---|---|---|
0003. 无重复字符的最长子串 |
Longest Substring Without Repeating Characters | Solution |
0005. 最长回文子串 |
Longest Palindromic Substring | Solution |
0006. Z 字形变换 |
Zigzag Conversion | Solution |
0008. 字符串转换整数 (atoi) |
String to Integer (atoi) | Solution |
0125. 验证回文串 |
Valid Palindrome | Solution |
0179. 最大数 |
Largest Number | Soluton |
0344. 反转字符串 |
Reverse String | Solution |
0409. 最长回文串 |
Longest Palindrome | Solution |
0541. 反转字符串 II |
Reverse String II | Solution |
Binary Search
Subject | Source | Solution |
---|---|---|
0035. 搜索插入位置 |
Search Insert Position | Solution |
0069. x 的平方根 |
Sqrt(x) | Solution |
0162. 寻找峰值 |
Find Peak Element | Solution |
0367. 有效的完全平方数 |
Valid Perfect Square | Solution |
0704. 二分查找 |
Binary Search | Solution |
Divide and Conquer
Subject | Source | Solution |
---|---|---|
0169. 多数元素 |
Majority Element | Solution |
Dynamic Programming
Backtracking
Subject | Source | Solution |
---|---|---|
0036. 有效的数独 |
Valid Sudoku | Solution |
0037. 解数独 |
Sudoku Solver | |
0039. 组合总和 |
Combination Sum | |
0040. 组合总和 II |
Combination Sum II | |
0046. 全排列 |
Permutations | |
0047. 全排列 II |
Permutations II | |
0051. N 皇后 |
N-Queens | |
0052. N 皇后 II |
N-Queens II | |
0078. 子集 |
Subsets | |
0079. 单词搜索 |
Word Search | Solution |
0090. 子集 II |
Subsets II |
Stack
Subject | Source | Solution |
---|---|---|
0020. 有效的括号 |
Valid Parentheses | Solution |
0094. 二叉树的中序遍历 |
Binary Tree Inorder Traversal | Solution |
0496. 下一个更大元素 I |
Next Greater Element I | Solution |
0503. 下一个更大元素 II |
Next Greater Element II | Solution |
0739. 每日温度 |
Daily Temperatures | Solution |
Greedy
Sort
Bit Manipulation
Subject | Source | Solution |
---|---|---|
0029. 两数相除 |
Divide Two Integers | Solution |
0190. 颠倒二进制位 |
Reverse Bits | Solution |
0191. 位 1 的个数 |
Number of 1 Bits | Solution |
0231. 2 的幂 |
Power of Two | Solution |
0338. 比特位计数 |
Counting Bits | Solution |
0461. 汉明距离 |
Hamming Distance | Solution |
Tree
Subject | Source | Solution |
---|---|---|
0020. 括号生成 |
Generate Parentheses | Solution |
0098. 验证二叉搜索树 |
Validate Binary Search Tree | Solution |
0100. 相同的树 |
Same Tree | Solution |
0102. 二叉树的层序遍历 |
Binary Tree Level Order Traversal | Solution |
0103. 二叉树的锯齿形层次遍历 |
Binary Tree Zigzag Level Order Traversal | Solution |
0104. 二叉树的最大深度 |
Maximum Depth of Binary Tree | Solution |
0199. 二叉树的右视图 |
Binary Tree Right Side View | Solution |
0230. 二叉搜索树中第 K 小的元素 |
Kth Smallest Element in a BST | Solution |
0235. 二叉搜索树的最近公共祖先 |
Lowest Common Ancestor of a Binary Search Tree | Solution |
0236. 二叉树的最近公共祖先 |
Lowest Common Ancestor of a Binary Tree | Solution |
0450. 删除二叉搜索树中的节点 |
Delete Node in a Binary Search Tree | Solution |
0515. 在每个树行中找最大值 |
Find Largest Value in Each Tree Row | Solution |
0637. 二叉树的层平均值 |
Average of Levels in Binary Tree | Solution |
0700. 二叉搜索树中的搜索 |
Search in a Binary Search Tree | Solution |
0701. 二叉搜索树中的插入操作 |
Insert into a Binary Search Tree | Solution |
0993. 二叉树的堂兄弟节点 |
Cousins in Binary Tree | Solution |
Depth-First Search
Breadth-First Search
Union Find
Subject | Source | Solution |
---|---|---|
0200. 岛屿数量 |
Number of Islands | Solution |
Graph
Subject | Source | Solution |
---|
Design
Subject | Source | Solution |
---|---|---|
0208. 实现 Trie(前缀树) |
Implement Trie (Prefix Tree) | Solution |
0225. 用队列实现栈 |
Implement Stack using Queues | Solution |
0232. 用栈实现队列 |
Implement Queue using Stacks | Solution |
Topological Sort
Subject | Source | Solution |
---|
Trie
Subject | Source | Solution |
---|
Binary Indexed Tree
Subject | Source | Solution |
---|
Segment Tree
Subject | Source | Solution |
---|
Binary Search Tree
Subject | Source | Solution |
---|---|---|
0278. 第一个错误的版本 |
First Bad Version | Solution |
Recursion
Subject | Source | Solution |
---|---|---|
0509. 斐波那契数 |
Fibonacci Number | Solution |
Brainteaser
Subject | Source | Solution |
---|
Memoization
Subject | Source | Solution |
---|
Queue
Subject | Source | Solution |
---|---|---|
0239. 滑动窗口最大值 |
Sliding Window Maximum | Solution |
Reservoir Sampling
Subject | Source | Solution |
---|
Ordered Map
Subject | Source | Solution |
---|
Geometry
Subject | Source | Solution |
---|
Rejection Sampling
Subject | Source | Solution |
---|
Sliding Window
Subject | Source | Solution |
---|---|---|
0003. 无重复字符的最长子串 |
Longest Substring Without Repeating Characters | Solution |
0076. 最小覆盖子串 |
Minimum Window Substring | Solution |
0438. 找到字符串中所有字母异位词 |
Find All Anagrams in a String | Solution |
0567. 字符串的排列 |
Permutation in String | Solution |
Line Sweep
Subject | Source | Solution |
---|
Rolling Hash
Subject | Source | Solution |
---|
Suffix Array
Subject | Source | Solution |
---|
Database
Subject | Source | Solution |
---|
Shell
Subject | Source | Solution |
---|
Concurrency
Subject | Source | Solution |
---|
Sorting
Subject | Source | Solution |
---|
Heap (Priority Queue)
Subject | Source | Solution |
---|---|---|
0295. 数据流的中位数 |
Find Median from Data Stream | Solution |
0347. 前 K 个高频元素 |
Top K Frequent Elements | Solution |
0378. 有序矩阵中第 K 小的元素 |
Kth Smallest Element in a Sorted Matrix | Solution |
0703. 数据流中的第 K 大元素 |
Kth Largest Element in a Stream | Solution |
Merge Sort
Subject | Source | Solution |
---|
String Matching
Subject | Source | Solution |
---|
Matrix
Subject | Source | Solution |
---|
Monotonic Stack
Subject | Source | Solution |
---|
Simulation
Subject | Source | Solution |
---|
Combinatorics
Subject | Source | Solution |
---|
Binary Tree
Subject | Source | Solution |
---|---|---|
0101. 对称二叉树 |
Symmetric Tree | Solution |
0124. 二叉树最大路径和 |
Binary Tree Maximum Path Sum | Solution |
0226. 翻转二叉树 |
Invert Binary Tree | Solution |
Doubly-Linked List
Subject | Source | Solution |
---|
Interactive
Subject | Source | Solution |
---|
Bucket Sort
Subject | Source | Solution |
---|
Radix Sort
Subject | Source | Solution |
---|
Counting
Subject | Source | Solution |
---|
Data Stream
Subject | Source | Solution |
---|
Iterator
Subject | Source | Solution |
---|
Hash Function
Subject | Source | Solution |
---|
Enumeration
Subject | Source | Solution |
---|
Number Theory
Subject | Source | Solution |
---|
Prefix Sum
Subject | Source | Solution |
---|
Quickselect
Subject | Source | Solution |
---|
Ordered Set
Subject | Source | Solution |
---|
Monotonic Queue
Subject | Source | Solution |
---|
Counting Sort
Subject | Source | Solution |
---|
Game Theory
Subject | Source | Solution |
---|
Eulerian Circuit
Subject | Source | Solution |
---|
Randomized
Subject | Source | Solution |
---|
Shortest Path
Subject | Source | Solution |
---|
Bitmask
Subject | Source | Solution |
---|
Probability and Statistics
Subject | Source | Solution |
---|
Minimum Spanning Tree
Subject | Source | Solution |
---|
Biconnected Component
Subject | Source | Solution |
---|
Strongly Connected Component
Subject | Source | Solution |
---|