# JavaScript 算法练习
[](https://github.com/yi-ge/js-practice/blob/master/LICENSE)


[](https://github.com/yi-ge/js-practice)
[](https://gitpod.io/#https://github.com/yi-ge/js-practice)

[](https://github.com/standard/standard)
LeetCode 与 LintCode 解题记录。此为个人练习仓库,代码中对重要思想进行了注释,但是没有详细的解题思路。需解题思路请移步其它仓库,很抱歉。
每一道题都对应写有测试用例,但可能不够完整。如果您发现错误,欢迎给我留言,谢谢!
## 字符串
- [反转字符串中的单词](src/string/reverse-words-in-a-string.js)
- LeetCode 557. 反转字符串中的单词 III
- LintCode 1173. 反转字符串 III
- [计数二进制子串](src/string/count-binary-substrings.js)
- LeetCode 696. 计数二进制子串
- LintCode 1079. 连续子串计数
- [重复的子串](src/string/repeated-substring-pattern.js)
- LeetCode 459. 重复的子字符串
- LintCode 1227. 重复的子串模式
- [正则表达式匹配](src/string/regular-expression-matching.js)
- LeetCode 10. 正则表达式匹配
- LintCode 154. 正则表达式匹配
- [恢复 IP 地址](src/string/restore-ip-addresses.js)
- LeetCode 93. 复原 IP 地址
- LintCode 426. 恢复 IP 地址
- [存在重复元素](src/string/contains-duplicate.js)
- LeetCode 217. 存在重复元素
- [判断字符串是否没有重复字符](src/string/unique-characters.js)
- LintCode 157. 判断字符串是否没有重复字符
- [比较字符串](src/string/compare-strings.js)
- LintCode 55. 比较字符串
- [最长无重复字符的子串](src/string/longest-substring-without-repeating-characters.js)
- LeetCode 3. 无重复字符的最长子串
- LintCode 384. 最长无重复字符的子串
- [最大数](src/string/largest-number.js)
- LeetCode 179. 最大数
- LintCode 184. 最大数
- [实现string2int()函数](src/string/string2int.js)
- 面试题参考思路,不严谨实现 廖雪峰 不要使用JavaScript内置的parseInt()函数,利用map和reduce操作实现一个string2int()函数。
- [左旋转字符串](src/string/zuo-xuan-zhuan-zi-fu-chuan-lcof.js)
- LeetCode 面试题58 - II. 左旋转字符串
- [最后一个单词的长度](src/string/length-of-last-word.js)
- LeetCode 58. 最后一个单词的长度
- LintCode 422. 最后一个单词的长度
- [整数转罗马数字](src/string/integer-to-roman.js)
- LeetCode 12. 整数转罗马数字
- LintCode 418. 整数转罗马数字
- [罗马数字转整数](src/string/roman-to-integer.js)
- LeetCode 13. 罗马数字转整数
- LintCode 419. 罗马数字转整数
- [验证回文字符串 Ⅱ](src/string/valid-palindrome-ii.js)
- LeetCode 680. 验证回文字符串 Ⅱ
- LintCode 891. 有效回文 II
- [IP地址无效化](src/string/defanging-an-ip-address.js)
- LeetCode 1108. IP 地址无效化
- [每个元音包含偶数次的最长子字符串](src/string/find-the-longest-substring-containing-vowels-in-even-counts.js)
- LeetCode 1371. 每个元音包含偶数次的最长子字符串
## 数组/队列/集合/映射
- [电话号码的字母组合](src/array/letter-combinations-of-a-phone-number.js)
- LeetCode 17. 电话号码的字母组合
- LintCode 425. 电话号码的字母组合
- [卡牌分组](src/array/x-of-a-kind-in-a-deck-of-cards.js)
- LeetCode 914. 卡牌分组
- [删除排序数组中的重复项](src/array/remove-duplicates-from-sorted-array.js)
- LeetCode 26. 删除排序数组中的重复项
- LintCode 100. 删除排序数组中的重复数字
- [能否种花](src/array/can-place-flowers.js)
- LeetCode 605. 种花问题
- LintCode 1138. 能否放置花
- [循环升序数组](src/array/loop-asc-array.js)
- 假设有一个升序数组,经过不确定长度的偏移,得到一个新的数组,我们称为循环升序数组。
(例如:[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
- [循环数组中的环-暂无解](src/array/circular-array-loop.js)
- LeetCode 457. 环形数组循环
- LintCode 1229. 循环数组中的环
- [格雷编码](src/array/gray-code.js)
- LeetCode 89. 格雷编码
- LintCode 411. 格雷编码
- [数组划分](src/array/partition-array.js)
- LintCode 31. 数组划分
- [冒泡排序](src/array/bubble-sort.js)
- [选择排序](src/array/select-sort.js)
- [按奇偶排序数组](src/array/sort-array-by-parity.js)
- LeetCode 922. 按奇偶排序数组 II
- [数组中的第 K 个最大元素](src/array/kth-largest-element-in-an-array.js)
- LeetCode 215. 数组中的第 K 个最大元素
- LeetCode 414. 第三大的数【相似,需去重】
- LintCode 5. 第 k 大元素
- LintCode 606. 第 K 大的元素 II
- LintCode 544. 前 K 大数【相似】
- LintCode 479. 数组第二大数【相似】
- [最大间距](src/array/maximum-gap.js)
- LeetCode 164. 最大间距
- LintCode 400. 最大间距
- [缺失的第一个正数](src/array/first-missing-positive.js)
- LeetCode 41. 缺失的第一个正数
- LintCode 189. 丢失的第一个正整数
- LintCode 681. 缺失的第一个素数【相似】
- [缺失的第一个素数](src/array/first-missing-prime-number.js)
- LintCode 681. 缺失的第一个素数
- [串联所有单词的子串](src/array/substring-with-concatenation-of-all-words.js)
- LeetCode 30. 串联所有单词的子串
- LintCode 1362. 包含所有单词连接的子串
- [买卖股票的最佳时机 II](src/array/best-time-to-buy-and-sell-stock-ii.js)
- LeetCode 122. 买卖股票的最佳时机 II
- LintCode 150. 买卖股票的最佳时机 II
- [搜索插入位置](src/array/search-insert-position.js)
- LeetCode 35. 搜索插入位置
- LintCode 20. 搜索插入位置
- [二分查找](src/array/binary-search.js)
- LeetCode 35. 二分查找
- LintCode 20. 二分查找
- [查找常用字符](src/array/find-common-characters.js)
- LeetCode 1002. 查找常用字符
- [01 矩阵](src/array/01-matrix.js)
- LeetCode 542. 01 矩阵
- LintCode 974. 01 矩阵
- [合并区间](src/array/merge-intervals.js)
- LeetCode 56. 合并区间
- LintCode 156. 合并区间
- [跳跃游戏](src/array/jump-game.js)
- LeetCode 55. 跳跃游戏
- LintCode 116. 跳跃游戏
- [盛最多水的容器](src/array/container-with-most-water.js)
- LeetCode 11. 盛最多水的容器
- LintCode 383. 装最多水的容器
- [统计重复个数](src/array/count-the-repetitions.js)
- LeetCode 466. 统计重复个数
- LintCode 1224. 统计重复个数
- [岛屿的个数](src/array/number-of-islands.js)
- LeetCode 200. 岛屿数量
- LintCode 433. 岛屿的个数
- [统计「优美子数组」](src/array/count-number-of-nice-subarrays.js)
- LeetCode 1248. 统计「优美子数组」
- [主元素](src/array/majority-element.js)
- LeetCode 面试题 17.10. 主要元素
- LintCode 46. 主元素
- [逆序对](src/array/reverse-pairs.js)
- LeetCode 面试题51. 数组中的逆序对
- LintCode 532. 逆序对
- [搜索旋转排序数组](src/array/search-in-rotated-sorted-array.js)
- LeetCode 33. 搜索旋转排序数组
- LintCode 62. 搜索旋转排序数组
- [数组中数字出现的次数](src/array/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof.js)
- LeetCode 面试题56 - I. 数组中数字出现的次数
- [只出现一次的数字](src/array/single-number.js)
- LeetCode 136. 只出现一次的数字
- [山脉数组中查找目标值](src/array/find-in-mountain-array.js)
- LeetCode 1095. 山脉数组中查找目标值
- LeetCode 852. 山脉数组的峰顶索引
- LintCode 585. 山脉序列中的最大值
- [快乐数](src/array/happy-number.js)
- LeetCode 202. 快乐数
- LintCode 488. 快乐数
- [最大子序和](src/array/maximum-subarray.js)
- LeetCode 53. 最大子序和
- LeetCode 面试题42. 连续子数组的最大和
- LintCode 41. 最大子数组
- [跳跃游戏II](src/array/jump-game-ii.js)
- LeetCode 45. 跳跃游戏 II
- LintCode 117. 跳跃游戏 II
- [最大数和最小数](src/array/maximum-and-minimum.js)
- LintCode 770. 最大数和最小数
- [最低票价](src/array/minimum-cost-for-tickets.js)
- LeetCode 983. 最低票价
- [最大正方形](src/array/maximal-square.js)
- LeetCode 221. 最大正方形
- LintCode 436. 最大正方形
- [数据流中第一个唯一的数字](src/array/first-unique-number-in-data-stream.js)
- LintCode 685. 数据流中第一个唯一的数字
- [第一个只出现一次的字符](src/array/first-unique-character-in-a-string.js)
- LeetCode 面试题50. 第一个只出现一次的字符
- LeetCode 387. 字符串中的第一个唯一字符
- LintCode 209. 第一个只出现一次的字符
- [乘积最大子数组](src/array/maximum-product-subarray.js)
- LeetCode 152. 乘积最大子数组
- LintCode 191. 乘积最大子序列
- [最高频率的IP](src/array/highest-frequency-ip.js)
- LintCode 1613. 最高频率的IP
## 栈
- [最大矩阵](src/stack/maximal-rectangle.js)
- LeetCode 85. 最大矩阵
- LintCode 510. 最大矩阵
- [最小栈](src/stack/min-stack.js)
- LeetCode 155. 最小栈
- LintCode 12. 带最小值操作的栈
## 数学
- [阶乘后的零](src/math/factorial-trailing-zeroes.js)
- LeetCode 172. 阶乘后的零
- LintCode 2. 尾部的零
- [丑数 II](src/math/ugly-number-ii.js)
- LeetCode 264. 丑数 II
- LintCode 4. 丑数 II
- [面试题 08.11. 硬币](src/math/coin-lcci.js)
- LeetCode 面试题 08.11. 硬币
- [全排列](src/math/permutations.js)
- LeetCode 46. 全排列
- LintCode 15. 全排列
- [最大数值](src/math/maximum-lcci.js)
- LeetCode 面试题 16.07. 最大数值
- [回文数](src/math/palindrome-number.js)
- LeetCode 9. 回文数
- LintCode 491. 回文数
- [Pow(x, n)](src/math/powx-n.js)
- LeetCode 50. Pow(x, n)
- LintCode 428. x的n次幂
- [和为K的子数组](src/math/subarray-sum-equals-k.js)
- LeetCode 560. 和为K的子数组
- LintCode 838. 子数组和为K
## 堆
- [超级丑数](src/stack/super-ugly-number.js)【未完成】
- LeetCode 313. 超级丑数
- LintCode 518. 超级丑数
## 树
- [二叉树的右视图](src/tree/binary-tree-right-side-view.js)
- LeetCode 199. 二叉树的右视图
- LintCode 760. 二叉树的右视图
- [验证二叉搜索树](src/tree/validate-binary-search-tree.js)
- LeetCode 98. 验证二叉搜索树
- LintCode 95. 验证二叉查找树
- [二叉树的最近公共祖先](src/tree/lowest-common-ancestor-of-a-binary-tree.js)
- LeetCode 236. 二叉树的最近公共祖先
- LintCode 88. 最近公共祖先
- [另一个树的子树](src/tree/subtree-of-another-tree.js)
- LeetCode 572. 另一个树的子树
- LintCode 1165. 另一个树的子树
- [二叉树的层序遍历](src/tree/binary-tree-level-order-traversal.js)
- LeetCode 102. 二叉树的层序遍历
- LintCode 69. 二叉树的层次遍历
- [二叉树的层次遍历 II](src/tree/binary-tree-level-order-traversal-ii.js)
- LeetCode 107. 二叉树的层次遍历 II
- LintCode 70. 二叉树的层次遍历 II
## 链表
- [合并K个排序链表](src/list/merge-k-sorted-lists.js)
- LeetCode 23. 合并K个排序链表
- LintCode 104. 合并k个排序链表
- [合并两个有序链表](src/list/merge-two-sorted-lists.js)
- LeetCode 21. 合并两个有序链表
- LeetCode 面试题25. 合并两个排序的链表
- LintCode 165. 合并两个排序链表
- [链表排序](src/list/sort-list.js)
- LeetCode 148. 排序链表
- LintCode 98. 链表排序
- [环形链表](src/list/linked-list-cycle.js)
- LeetCode 141. 环形链表
- LintCode 102. 带环链表
- [链表的中间结点](src/list/middle-of-the-linked-list.js)
- LeetCode 876. 链表的中间结点
- LintCode 1609. 链表的中间结点
- [K个一组翻转链表](src/list/reverse-nodes-in-k-group.js)
- LeetCode 25. K 个一组翻转链表
- LintCode 450. K组翻转链表
## 图
- [课程表](src/graphs/course-schedule-ii.js)
- LeetCode 210. 课程表 II
- LeetCode 207. 课程表
- LintCode 615. 课程表