JavaScript 算法练习 - LeetCode 与 LintCode 解题记录。
.github/workflows | ||
.vscode | ||
src | ||
test | ||
.babelrc | ||
.eslintrc.js | ||
.gitignore | ||
.gitpod.yml | ||
.travis.yml | ||
LICENSE | ||
package.json | ||
README.md | ||
yarn.lock |
JavaScript 算法练习
LeetCode 与 LintCode 解题记录。此为个人练习仓库,代码中对重要思想进行了注释,但是没有详细的解题思路。需解题思路请移步其它仓库,很抱歉。
每一道题都对应写有测试用例,但可能不够完整。如果您发现错误,欢迎给我留言,谢谢!
字符串
-
- LeetCode 557. 反转字符串中的单词 III https://leetcode-cn.com/problems/reverse-words-in-a-string-iii/
- LintCode 1173. 反转字符串 III https://www.lintcode.com/problem/reverse-words-in-a-string-iii/description
-
- LeetCode 696. 计数二进制子串 https://leetcode-cn.com/problems/count-binary-substrings/
- LintCode 1079. 连续子串计数 https://www.lintcode.com/problem/count-binary-substrings/description
-
- LeetCode 459. 重复的子字符串 https://leetcode-cn.com/problems/repeated-substring-pattern/
- LintCode 1227. 重复的子串模式 https://www.lintcode.com/problem/repeated-substring-pattern/description
-
- LeetCode 10. 正则表达式匹配 https://leetcode-cn.com/problems/regular-expression-matching/
- LintCode 154. 正则表达式匹配 https://www.lintcode.com/problem/regular-expression-matching/description
-
- LeetCode 93. 复原 IP 地址 https://leetcode-cn.com/problems/restore-ip-addresses/
- LintCode 426. 恢复 IP 地址 https://www.lintcode.com/problem/restore-ip-addresses/description
-
- LeetCode 217. 存在重复元素 https://leetcode-cn.com/problems/contains-duplicate/
-
- LintCode 157. 判断字符串是否没有重复字符 https://www.lintcode.com/problem/unique-characters/description
-
- LintCode 55. 比较字符串 https://www.lintcode.com/problem/compare-strings/description
-
- LeetCode 3. 无重复字符的最长子串 https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
- LintCode 384. 最长无重复字符的子串 https://www.lintcode.com/problem/longest-substring-without-repeating-characters/description
-
- LeetCode 179. 最大数 https://leetcode-cn.com/problems/largest-number/
- LintCode 184. 最大数 https://www.lintcode.com/problem/largest-number/description
-
- 面试题参考思路,不严谨实现 廖雪峰 不要使用 JavaScript 内置的 parseInt()函数,利用 map 和 reduce 操作实现一个 string2int()函数。 https://www.liaoxuefeng.com/wiki/1022910821149312/1024322552460832
-
- LeetCode 面试题 58 - II. 左旋转字符串 https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof/
-
- LeetCode 58. 最后一个单词的长度 https://leetcode-cn.com/problems/length-of-last-word/
- LintCode 422. 最后一个单词的长度 https://www.lintcode.com/problem/length-of-last-word/description
-
- LeetCode 12. 整数转罗马数字 https://leetcode-cn.com/problems/integer-to-roman/
- LintCode 418. 整数转罗马数字 https://www.lintcode.com/problem/integer-to-roman/description
-
- LeetCode 13. 罗马数字转整数 https://leetcode-cn.com/problems/roman-to-integer/
- LintCode 419. 罗马数字转整数 https://www.lintcode.com/problem/roman-to-integer/description
-
- LeetCode 680. 验证回文字符串 Ⅱ https://leetcode-cn.com/problems/valid-palindrome-ii/
- LintCode 891. 有效回文 II https://www.lintcode.com/problem/valid-palindrome-ii/description
-
- LeetCode 1108. IP 地址无效化 https://leetcode-cn.com/problems/defanging-an-ip-address/
-
- LeetCode 5. 最长回文子串 https://leetcode-cn.com/problems/longest-palindromic-substring/
- LintCode 200. 最长回文子串 https://www.lintcode.com/problem/longest-palindromic-substring/
-
- LeetCode 1371. 每个元音包含偶数次的最长子字符串 https://leetcode-cn.com/problems/find-the-longest-substring-containing-vowels-in-even-counts/
-
- LeetCode 76. 最小覆盖子串 https://leetcode-cn.com/problems/minimum-window-substring/
- LintCode 32. 最小子串覆盖 https://www.lintcode.com/problem/minimum-window-substring/description
-
- LeetCode 5416. 检查单词是否为句中其他单词的前缀 https://leetcode-cn.com/problems/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/
-
- LeetCode 5417. 定长子串中元音的最大数目 https://leetcode-cn.com/problems/maximum-number-of-vowels-in-a-substring-of-given-length/
-
- LeetCode 14. 最长公共前缀 https://leetcode-cn.com/problems/longest-common-prefix/
- LintCode 78. 最长公共前缀 https://www.lintcode.com/problem/longest-common-prefix/description
数组/队列/集合/映射
-
- LeetCode 17. 电话号码的字母组合 https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/
- LintCode 425. 电话号码的字母组合 https://www.lintcode.com/problem/letter-combinations-of-a-phone-number/description
-
- LeetCode 914. 卡牌分组 https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards/
-
- LeetCode 26. 删除排序数组中的重复项 https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/
- LintCode 100. 删除排序数组中的重复数字 https://www.lintcode.com/problem/remove-duplicates-from-sorted-array/description
-
- LeetCode 605. 种花问题 https://leetcode-cn.com/problems/can-place-flowers/
- LintCode 1138. 能否放置花 https://www.lintcode.com/problem/can-place-flowers/description
-
-
假设有一个升序数组,经过不确定长度的偏移,得到一个新的数组,我们称为循环升序数组。 (例如:[0, 3, 4, 6, 7] 可能变成 [6, 7, 0, 3, 4]) 给定一个数字和一个循环升序数组,判断这个数字是否在这个数组内,在的话返回 true,否则返回 false。要求时间复杂度为 O(logN)
示例 1: 输入:nums = [6, 7, 0, 3, 4], target = 0 输出:true
示例 2: 输入:nums = [6, 7, 0, 3, 4], target = 5 输出:false
-
-
- LeetCode 457. 环形数组循环 https://leetcode-cn.com/problems/circular-array-loop/
- LintCode 1229. 循环数组中的环 https://www.lintcode.com/problem/circular-array-loop/description
-
- LeetCode 89. 格雷编码 https://leetcode-cn.com/problems/gray-code/
- LintCode 411. 格雷编码 https://www.lintcode.com/problem/gray-code/description
-
- LintCode 31. 数组划分 https://www.lintcode.com/problem/partition-array/description
-
- LeetCode 922. 按奇偶排序数组 II https://leetcode-cn.com/problems/sort-array-by-parity-ii/
-
- LeetCode 215. 数组中的第 K 个最大元素 https://leetcode-cn.com/problems/kth-largest-element-in-an-array/
- LeetCode 414. 第三大的数【相似,需去重】 https://leetcode-cn.com/problems/third-maximum-number/submissions/
- LintCode 5. 第 k 大元素 https://www.lintcode.com/problem/kth-largest-element/description
- LintCode 606. 第 K 大的元素 II https://www.lintcode.com/problem/kth-largest-element-ii/description
- LintCode 544. 前 K 大数【相似】 https://www.lintcode.com/problem/top-k-largest-numbers/description
- LintCode 479. 数组第二大数【相似】 https://www.lintcode.com/problem/second-max-of-array/description
-
- LeetCode 164. 最大间距 https://leetcode-cn.com/problems/maximum-gap/
- LintCode 400. 最大间距 https://www.lintcode.com/problem/maximum-gap/
-
- LeetCode 41. 缺失的第一个正数 https://leetcode-cn.com/problems/first-missing-positive/
- LintCode 189. 丢失的第一个正整数 https://www.lintcode.com/problem/first-missing-positive/description
- LintCode 681. 缺失的第一个素数【相似】 https://www.lintcode.com/problem/first-missing-prime-number/description
-
- LintCode 681. 缺失的第一个素数 https://www.lintcode.com/problem/first-missing-prime-number/description
-
- LeetCode 30. 串联所有单词的子串 https://leetcode-cn.com/problems/substring-with-concatenation-of-all-words/
- LintCode 1362. 包含所有单词连接的子串 https://www.lintcode.com/problem/substring-with-concatenation-of-all-words/description
-
- LeetCode 122. 买卖股票的最佳时机 II https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/
- LintCode 150. 买卖股票的最佳时机 II https://www.lintcode.com/problem/best-time-to-buy-and-sell-stock-ii/description
-
- LeetCode 35. 搜索插入位置 https://leetcode-cn.com/problems/search-insert-position/
- LintCode 20. 搜索插入位置 https://www.lintcode.com/problem/search-insert-position/description
-
- LeetCode 35. 二分查找 https://leetcode-cn.com/problems/binary-search/
- LintCode 20. 二分查找 https://www.lintcode.com/problem/first-position-of-target/description
-
- LeetCode 1002. 查找常用字符 https://leetcode-cn.com/problems/find-common-characters/
-
- LeetCode 542. 01 矩阵 https://leetcode-cn.com/problems/01-matrix/
- LintCode 974. 01 矩阵 https://www.lintcode.com/problem/01-matrix/description
-
- LeetCode 56. 合并区间 https://leetcode-cn.com/problems/merge-intervals/
- LintCode 156. 合并区间 https://www.lintcode.com/problem/merge-intervals/description
-
- LeetCode 55. 跳跃游戏 https://leetcode-cn.com/problems/jump-game/
- LintCode 116. 跳跃游戏 https://www.lintcode.com/problem/jump-game/description
-
- LeetCode 11. 盛最多水的容器 https://leetcode-cn.com/problems/container-with-most-water/
- LintCode 383. 装最多水的容器 https://www.lintcode.com/problem/container-with-most-water/description
-
- LeetCode 466. 统计重复个数 https://leetcode-cn.com/problems/count-the-repetitions/
- LintCode 1224. 统计重复个数 https://www.lintcode.com/problem/count-the-repetitions/description
-
- LeetCode 200. 岛屿数量 https://leetcode-cn.com/problems/number-of-islands/
- LintCode 433. 岛屿的个数 https://www.lintcode.com/problem/number-of-islands/description
-
- LeetCode 1248. 统计「优美子数组」 https://leetcode-cn.com/problems/count-number-of-nice-subarrays/
-
- LeetCode 面试题 17.10. 主要元素 https://leetcode-cn.com/problems/find-majority-element-lcci/
- LintCode 46. 主元素 https://www.lintcode.com/problem/majority-element/description
-
- LeetCode 面试题 51. 数组中的逆序对 https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/
- LintCode 532. 逆序对 https://www.lintcode.com/problem/reverse-pairs/description
-
- LeetCode 33. 搜索旋转排序数组 https://leetcode-cn.com/problems/search-in-rotated-sorted-array/
- LintCode 62. 搜索旋转排序数组 https://www.lintcode.com/problem/search-in-rotated-sorted-array/description
-
- LeetCode 面试题 56 - I. 数组中数字出现的次数 https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/
-
- LeetCode 136. 只出现一次的数字 https://leetcode-cn.com/problems/single-number/
-
- LeetCode 1095. 山脉数组中查找目标值 https://leetcode-cn.com/problems/find-in-mountain-array/
- LeetCode 852. 山脉数组的峰顶索引 https://leetcode-cn.com/problems/peak-index-in-a-mountain-array/
- LintCode 585. 山脉序列中的最大值 https://www.lintcode.com/problem/maximum-number-in-mountain-sequence/description
-
- LeetCode 202. 快乐数 https://leetcode-cn.com/problems/happy-number/
- LintCode 488. 快乐数 https://www.lintcode.com/problem/happy-number/description
-
- LeetCode 53. 最大子序和 https://leetcode-cn.com/problems/maximum-subarray/
- LeetCode 面试题 42. 连续子数组的最大和 https://leetcode-cn.com/problems/lian-xu-zi-shu-zu-de-zui-da-he-lcof/
- LintCode 41. 最大子数组 https://www.lintcode.com/problem/maximum-subarray/description
-
- LeetCode 45. 跳跃游戏 II https://leetcode-cn.com/problems/jump-game-ii/
- LintCode 117. 跳跃游戏 II https://www.lintcode.com/problem/jump-game-ii/description
-
- LintCode 770. 最大数和最小数 https://www.lintcode.com/problem/maximum-and-minimum/description
-
- LeetCode 983. 最低票价 https://leetcode-cn.com/problems/minimum-cost-for-tickets/
-
- LeetCode 221. 最大正方形 https://leetcode-cn.com/problems/maximal-square/
- LintCode 436. 最大正方形 https://www.lintcode.com/problem/maximal-square/description
-
- LintCode 685. 数据流中第一个唯一的数字 https://www.lintcode.com/problem/first-unique-number-in-data-stream/description
-
- LeetCode 面试题 50. 第一个只出现一次的字符 https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof/
- LeetCode 387. 字符串中的第一个唯一字符 https://leetcode-cn.com/problems/first-unique-character-in-a-string/
- LintCode 209. 第一个只出现一次的字符 https://www.lintcode.com/problem/first-unique-character-in-a-string/description
-
- LeetCode 152. 乘积最大子数组 https://leetcode-cn.com/problems/maximum-product-subarray/
- LintCode 191. 乘积最大子序列 https://www.lintcode.com/problem/maximum-product-subarray/description
-
- LintCode 1613. 最高频率的 IP https://www.lintcode.com/problem/highest-frequency-ip/description
-
- LeetCode 860. 柠檬水找零 https://leetcode-cn.com/problems/lemonade-change/
- LintCode 1509. 柠檬水找零 https://www.lintcode.com/problem/lemonade-change/description
-
- LeetCode 146. LRU 缓存机制 https://leetcode-cn.com/problems/lru-cache/
- LintCode 134. LRU 缓存策略 https://www.lintcode.com/problem/lru-cache/description
-
- LeetCode 287. 寻找重复数 https://leetcode-cn.com/problems/find-the-duplicate-number/
- LintCode 633. 寻找重复的数 https://www.lintcode.com/problem/find-the-duplicate-number/description
-
- LeetCode 974. 和可被 K 整除的子数组 https://leetcode-cn.com/problems/subarray-sums-divisible-by-k/
-
- LeetCode 198. 打家劫舍 https://leetcode-cn.com/problems/house-robber/
- LintCode 392. 打劫房屋 https://www.lintcode.com/problem/house-robber/description
-
- LeetCode 1431. 拥有最多糖果的孩子 https://leetcode-cn.com/problems/kids-with-the-greatest-number-of-candies/
-
- LeetCode 238. 除自身以外数组的乘积 https://leetcode-cn.com/problems/product-of-array-except-self/
- LintCode 1310. 数组除了自身的乘积 https://www.lintcode.com/problem/product-of-array-except-self/description
-
- LeetCode 739. 每日温度 https://leetcode-cn.com/problems/daily-temperatures/
- LintCode 1060. 每日温度 https://www.lintcode.com/problem/daily-temperatures/description
-
- LeetCode 718. 最长重复子数组 https://leetcode-cn.com/problems/maximum-length-of-repeated-subarray/
- LintCode 79. 最长公共子串 https://www.lintcode.com/problem/longest-common-substring/description
-
- LeetCode 378. 有序矩阵中第 K 小的元素 https://leetcode-cn.com/problems/kth-smallest-element-in-a-sorted-matrix/
- LintCode 401. 排序矩阵中的从小到大第 k 个数 https://www.lintcode.com/problem/kth-smallest-number-in-sorted-matrix/description
栈
-
- LeetCode 85. 最大矩阵 https://leetcode-cn.com/problems/maximal-rectangle/
- LintCode 510. 最大矩阵 https://www.lintcode.com/problem/maximal-rectangle/description
-
- LeetCode 155. 最小栈 https://leetcode-cn.com/problems/min-stack/
- LintCode 12. 带最小值操作的栈 https://www.lintcode.com/problem/min-stack/description
-
- LeetCode 剑指 Offer 09. 用两个栈实现队列 https://leetcode-cn.com/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/
-
- LeetCode 394. 字符串解码 https://leetcode-cn.com/problems/decode-string/
- LintCode 575. 字符串解码 https://www.lintcode.com/problem/decode-string/description
数学
-
- LeetCode 172. 阶乘后的零 https://leetcode-cn.com/problems/factorial-trailing-zeroes/submissions/
- LintCode 2. 尾部的零 https://www.lintcode.com/problem/trailing-zeros/description
-
- LeetCode 264. 丑数 II https://leetcode-cn.com/problems/ugly-number-ii/
- LintCode 4. 丑数 II https://www.lintcode.com/problem/ugly-number-ii/description
-
- LeetCode 面试题 08.11. 硬币 https://leetcode-cn.com/problems/coin-lcci/
-
- LeetCode 46. 全排列 https://leetcode-cn.com/problems/permutations/
- LintCode 15. 全排列 https://www.lintcode.com/problem/permutations/description
-
- LeetCode 面试题 16.07. 最大数值 https://leetcode-cn.com/problems/maximum-lcci/
-
- LeetCode 9. 回文数 https://leetcode-cn.com/problems/palindrome-number/
- LintCode 491. 回文数 https://www.lintcode.com/problem/palindrome-number/description
-
- LeetCode 50. Pow(x, n) https://leetcode-cn.com/problems/powx-n/
- LintCode 428. x 的 n 次幂 https://www.lintcode.com/problem/powx-n/description
-
- LeetCode 560. 和为 K 的子数组 https://leetcode-cn.com/problems/subarray-sum-equals-k/
- LintCode 838. 子数组和为 K https://www.lintcode.com/problem/subarray-sum-equals-k/description
-
- LeetCode 507. 完美数 https://leetcode-cn.com/problems/perfect-number/
- LintCode 1199. 完美的数 https://www.lintcode.com/problem/perfect-number/description
-
- LeetCode 4. 寻找两个正序数组的中位数 https://leetcode-cn.com/problems/median-of-two-sorted-arrays/
- LintCode 65. 两个排序数组的中位数 https://www.lintcode.com/problem/median-of-two-sorted-arrays/description
-
- LeetCode 15. 三数之和 https://leetcode-cn.com/problems/3sum/
- LintCode 57. 三数之和 https://www.lintcode.com/problem/3sum/description
-
- LeetCode 67. 二进制求和 https://leetcode-cn.com/problems/add-binary/
- LintCode 408. 二进制求和 https://www.lintcode.com/problem/add-binary/description
堆
-
超级丑数【未完成】
- LeetCode 313. 超级丑数 https://leetcode-cn.com/problems/super-ugly-number/
- LintCode 518. 超级丑数 https://www.lintcode.com/problem/super-ugly-number/description
树
-
- LeetCode 199. 二叉树的右视图 https://leetcode-cn.com/problems/binary-tree-right-side-view/
- LintCode 760. 二叉树的右视图 https://www.lintcode.com/problem/binary-tree-right-side-view/description
-
- LeetCode 98. 验证二叉搜索树 https://leetcode-cn.com/problems/validate-binary-search-tree/
- LintCode 95. 验证二叉查找树 https://www.lintcode.com/problem/validate-binary-search-tree/description
-
- LeetCode 236. 二叉树的最近公共祖先 https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/
- LintCode 88. 最近公共祖先 https://www.lintcode.com/problem/lowest-common-ancestor-of-a-binary-tree/description
-
- LeetCode 572. 另一个树的子树 https://leetcode-cn.com/problems/subtree-of-another-tree/
- LintCode 1165. 另一个树的子树 https://www.lintcode.com/problem/subtree-of-another-tree/description
-
- LeetCode 102. 二叉树的层序遍历 https://leetcode-cn.com/problems/binary-tree-level-order-traversal/
- LintCode 69. 二叉树的层次遍历 https://www.lintcode.com/problem/binary-tree-level-order-traversal/description
-
- LeetCode 107. 二叉树的层次遍历 II https://leetcode-cn.com/problems/binary-tree-level-order-traversal-ii/
- LintCode 70. 二叉树的层次遍历 II https://www.lintcode.com/problem/binary-tree-level-order-traversal-ii/description
-
- LeetCode 105. 从前序与中序遍历序列构造二叉树 https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
- LintCode 73. 前序遍历和中序遍历树构造二叉树 https://www.lintcode.com/problem/construct-binary-tree-from-preorder-and-inorder-traversal/description
-
- LeetCode 108. 将有序数组转换为二叉搜索树 https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/
- LintCode 106. 有序链表转换为二叉搜索树 https://www.lintcode.com/problem/convert-sorted-list-to-binary-search-tree/description
-
- LeetCode 96. 不同的二叉搜索树 https://leetcode-cn.com/problems/unique-binary-search-trees/
链表
-
- LeetCode 23. 合并 K 个排序链表 https://leetcode-cn.com/problems/merge-k-sorted-lists/
- LintCode 104. 合并 k 个排序链表 https://www.lintcode.com/problem/merge-k-sorted-lists/description
-
- LeetCode 21. 合并两个有序链表 https://leetcode-cn.com/problems/merge-two-sorted-lists/
- LeetCode 面试题 25. 合并两个排序的链表 https://leetcode-cn.com/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof
- LintCode 165. 合并两个排序链表 https://www.lintcode.com/problem/merge-two-sorted-lists/description
-
- LeetCode 148. 排序链表 https://leetcode-cn.com/problems/sort-list/
- LintCode 98. 链表排序 https://www.lintcode.com/problem/sort-list/description
-
- LeetCode 141. 环形链表 https://leetcode-cn.com/problems/linked-list-cycle/
- LintCode 102. 带环链表 https://www.lintcode.com/problem/linked-list-cycle/description
-
- LeetCode 876. 链表的中间结点 https://leetcode-cn.com/problems/middle-of-the-linked-list/
- LintCode 1609. 链表的中间结点 https://www.lintcode.com/problem/middle-of-the-linked-list/description
-
- LeetCode 25. K 个一组翻转链表 https://leetcode-cn.com/problems/reverse-nodes-in-k-group/
- LintCode 450. K 组翻转链表 https://www.lintcode.com/problem/reverse-nodes-in-k-group/description
图
-
- LeetCode 210. 课程表 II https://leetcode-cn.com/problems/course-schedule-ii/
- LeetCode 207. 课程表 https://leetcode-cn.com/problems/course-schedule/
- LintCode 615. 课程表 https://www.lintcode.com/problem/course-schedule/description