Skip to content

imajinyun/leetcode-php

Repository files navigation

🚀 🐘 🌈 LeetCode with PHP 🔥

Build Status Build status Build codecov StyleCI Quality Gate Status Scrutinizer Code Quality FOSSA Status Version FOSSA Status

Requirements

  • PHP >= 8.0
  • PHPUnit >= 9.5

Usage

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

Contents

LeetCode

Array
Subject Source Solution
0001. 两数之和 Two Sum Solution
0118. 杨辉三角 Pascal's Triangle Solution
0026. 删除有序数组中的重复项 Remove Duplicates from Sorted Array Solution
0027. 移除元素 Remove Element Solution
0053. 最大子序和 Maximum Subarray Solution
0054. 螺旋矩阵 Spiral Matrix Solution
0059. 螺旋矩阵 II Spiral Matrix II Solution
0066. 加一 Plus One Solution
0088. 合并两个有序数组 Merge Sorted Array Solution
0118. 杨辉三角 Pascal's Triangle Solution
0119. 杨辉三角 II Pascal's Triangle II Solution
0163. 缺失的区间 Missing Ranges Solution
0167. 两数之和 II - 输入有序数组 Two Sum II - Input array is sorted
0169. 多数元素 Majority Element Solution
0189. 旋转数组 Rotate Array Solution
0215. 数组中的第 K 个最大元素 Kth Largest Element in an Array Solution
0217. 存在重复元素 Contains Duplicate Solution
0219. 存在重复元素 II Contains Duplicate II Solution
0228. 汇总区间 Summary Ranges
0238. Product of Array Except Self Solution
0243. 最短单词距离 Shortest Word Distance
0268. 丢失的数字 Missing Number
0283. 移动零 Move Zeroes Solution
0350. 两个数组的交集 II Intersection of Two Arrays II Solution
0384. 打乱数组 Shuffle an Array Solution
0414. 第三大的数 Third Maximum Number
0448. 找到所有数组中消失的数字 Find All Numbers Disappeared in an Array
0485. 最大连续 1 的个数 Max Consecutive Ones Solution
0509. 斐波那契数 Fibonacci Number Solution
0561. 数组拆分 I Array Partition I Solution
0566. 重塑矩阵 Reshape the Matrix Solution
0605. 种花问题 Can Place Flowers Solution
0628. 三个数的最大乘积 Maximum Product of Three Numbers
0643. 子数组最大平均数 I Maximum Average Subarray I
0661. 图片平滑器 Image Smoother Solution
0674. 最长连续递增序列 Longest Continuous Increasing Subsequence Solution
0697. 数组的度 Degree of an Array Solution
0717. 1 比特与 2 比特字符 1-bit and 2-bit Characters Solution
0724. 寻找数组的中心下标 Find Pivot Index Solution
0746. 使用最小花费爬楼梯 Min Cost Climbing Stairs Solution
0747. 至少是其他数字两倍的最大数 Largest Number At Least Twice of Others Solution
0766. 托普利茨矩阵 Toeplitz Matrix Solution
0830. 较大分组的位置 Positions of Large Groups Solution
0832. 翻转图像 Flipping an Image Solution
0867. 转置矩阵 Transpose Matrix Solution
0888. 公平的糖果棒交换 Fair Candy Swap Solution
0896. 单调数列 Monotonic Array Solution
0905. 按奇偶排序数组 Sort Array By Parity Solution
0914. 卡牌分组 X of a Kind in a Deck of Cards Solution
0922. 按奇偶排序数组 II Sort Array By Parity II Solution
0941. 有效的山脉数组 Valid Mountain Array Solution
0977. 有序数组的平方 Squares of a Sorted Array Solution
0985. 查询后的偶数和 Sum of Even Numbers After Queries Solution
0989. 数组形式的整数加法 Add to Array-Form of Integer Solution
0999. 可以被一步捕获的棋子数 Available Captures for Rook Solution
1002. 查找常用字符 Find Common Characters Solution
1013. 将数组分成和相等的三个部分 Partition Array Into Three Parts With Equal Sum Solution
1018. 可被 5 整除的二进制前缀 Binary Prefix Divisible By 5 Solution
1051. 高度检查器 Height Checker Solution
1064. 不动点 Fixed Point Solution
1085. 最小元素各数位之和 Sum of Digits in the Minimum Number Solution
1086. 前五科的均分 High Five Solution
1089. 复写零 Duplicate Zeros Solution
1099 小于 K 的两数之和 Two Sum Less Than K Solution
1122. 数组的相对排序 Relative Sort Array Solution
1128. 等价多米诺骨牌对的数量 Number of Equivalent Domino Pairs Solution
1150. 检查一个数是否在数组中占绝大多数 Check If a Number Is Majority Element in a Sorted Array Solution
1160. 拼写单词 Find Words That Can Be Formed by Characters Solution
1176. 健身计划评估 Diet Plan Performance Easy Solution
1184. 公交站间的距离 Distance Between Bus Stops Solution
1185. 一周中的第几天 Day of the Week Solution
1200. 最小绝对差 Minimum Absolute Difference Solution
1217. 玩筹码 Minimum Cost to Move Chips to The Same Position Solution
1232. 缀点成线 Check If It Is a Straight Line Solution
1243. 数组变换 Array Transformation Solution
1252. 奇数值单元格的数目 Cells with Odd Values in a Matrix Solution
1260. 二维网格迁移 Shift 2D Grid Solution
1266. 访问所有点的最小时间 Minimum Time Visiting All Points Solution
1275. Find Winner on a Tic Tac Toe Game Solution
1295. 统计位数为偶数的数字 Find Numbers with Even Number of Digits Solution
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
Subject Source Solution
0005. 最长回文子串 Longest Palindromic Substring Solution
0062. 不同路径 Unique Paths Solution
0063. 不同路径 II Unique Paths II Solution
0064. 最小路径和 Minimum Path Sum Solution
0070. 爬楼梯 Climbing Stairs Solution
0072. 编辑距离 Edit Distance
0120. 三角形最小路径和 Triangle Solution
0121. 买卖股票的最佳时机 Best Time to Buy and Sell Stock Solution
0122. 买卖股票的最佳时机 II Best Time to Buy and Sell Stock II Solution
0123. 买卖股票的最佳时机 III Best Time to Buy and Sell Stock III Solution
0128. 最长连续序列 Longest Consecutive Sequence
0152. 乘积最大子数组 Maximum Product Subarray Solution
0188. 买卖股票的最佳时机 IV Best Time to Buy and Sell Stock IV Solution
0213. 打家劫舍 II House Robber II Solution
0300. 最长上升子序列 Longest Increasing Subsequence
0322. 零钱兑换 Coin Change
0309. 佳买卖股票时机含冷冻期 Best Time to Buy and Sell Stock with Cooldown Solution
0673. 最长递增子序列的个数 Number of Longest Increasing Subsequence
0674. 最长连续递增序列 Longest Continuous Increasing Subsequence
0714. 买卖股票的最佳时机含手续费 Best Time to Buy and Sell Stock with Transaction Fee Solution
1143. 最长公共子序列 Longest Common Subsequence
1289. 下降路径最小和 II Minimum Falling Path Sum II Solution
1397. 找到所有好字符串 Find All Good Strings
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

剑指 Offer

程序员面试金典

License

FOSSA Status

Releases

No releases published

Packages

No packages published

Languages