add: 只出现一次的数字等

This commit is contained in:
yige authored and yi-ge committed 2020-04-28 18:36:18 +08:00
1 parent 930ff1be11
commit 8239e7afd5
106 files changed
+7978

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
+19
View File
@@ -0,0 +1,19 @@
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
ecmaVersion: 2017,
sourceType: 'module'
},
env: {
browser: true,
node: true
},
extends: ['standard', 'plugin:jest/recommended'],
rules: {
// allow async-await
'generator-star-spacing': 'off',
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
}
}
+31
View File
@@ -0,0 +1,31 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install -g yarn
- run: yarn install
- run: yarn test
env:
CI: true
+2
View File
@@ -0,0 +1,2 @@
tasks:
- init: yarn install
+7
View File
@@ -0,0 +1,7 @@
language: node_js
node_js:
- 13
script:
- yarn test
- yarn coverage:ci
+8
View File
@@ -0,0 +1,8 @@
{
"cSpell.words": [
"lcci",
"lcof",
"nums",
"zhong"
]
}
+260
View File
@@ -0,0 +1,260 @@
# JavaScript 算法练习
[![license](https://img.shields.io/github/license/yi-ge/js-practice.svg?style=flat-square)](https://github.com/yi-ge/js-practice/blob/master/LICENSE)
![Travis (.org)](https://img.shields.io/travis/yi-ge/js-practice?style=flat-square)
![Coveralls github](https://img.shields.io/coveralls/github/yi-ge/js-practice?style=flat-square)
[![GitHub last commit](https://img.shields.io/github/last-commit/yi-ge/js-practice.svg?style=flat-square)](https://github.com/yi-ge/js-practice)
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod&style=flat-square)](https://gitpod.io/#https://github.com/yi-ge/js-practice)
![Node.js CI](https://github.com/yi-ge/js-practice/workflows/Node.js%20CI/badge.svg)
[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard)
## 字符串
- [反转字符串中的单词](src/string/reverse-words-in-a-string.js)
- 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
- [计数二进制子串](src/string/count-binary-substrings.js)
- LeetCode 696. 计数二进制子串 https://leetcode-cn.com/problems/count-binary-substrings/
- LintCode 1079. 连续子串计数 https://www.lintcode.com/problem/count-binary-substrings/description
- [重复的子串](src/string/repeated-substring-pattern.js)
- LeetCode 459. 重复的子字符串 https://leetcode-cn.com/problems/repeated-substring-pattern/
- LintCode 1227. 重复的子串模式 https://www.lintcode.com/problem/repeated-substring-pattern/description
- [正则表达式匹配](src/string/regular-expression-matching.js)
- LeetCode 10. 正则表达式匹配 https://leetcode-cn.com/problems/regular-expression-matching/
- LintCode 154. 正则表达式匹配 https://www.lintcode.com/problem/regular-expression-matching/description
- [恢复 IP 地址](src/string/restore-ip-addresses.js)
- LeetCode 93. 复原 IP 地址 https://leetcode-cn.com/problems/restore-ip-addresses/
- LintCode 426. 恢复 IP 地址 https://www.lintcode.com/problem/restore-ip-addresses/description
- [存在重复元素](src/string/contains-duplicate.js)
- LeetCode 217. 存在重复元素 https://leetcode-cn.com/problems/contains-duplicate/
- [判断字符串是否没有重复字符](src/string/unique-characters.js)
- LintCode 157. 判断字符串是否没有重复字符 https://www.lintcode.com/problem/unique-characters/description
- [比较字符串](src/string/compare-strings.js)
- LintCode 55. 比较字符串 https://www.lintcode.com/problem/compare-strings/description
## 数组
- [电话号码的字母组合](src/array/letter-combinations-of-a-phone-number.js)
- 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
- [卡牌分组](src/array/x-of-a-kind-in-a-deck-of-cards.js)
- LeetCode 914. 卡牌分组 https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards/
- [删除排序数组中的重复项](src/array/remove-duplicates-from-sorted-array.js)
- 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
- [能否种花](src/array/can-place-flowers.js)
- LeetCode 605. 种花问题 https://leetcode-cn.com/problems/can-place-flowers/
- LintCode 1138. 能否放置花 https://www.lintcode.com/problem/can-place-flowers/description
- [循环升序数组](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. 环形数组循环 https://leetcode-cn.com/problems/circular-array-loop/
- LintCode 1229. 循环数组中的环 https://www.lintcode.com/problem/circular-array-loop/description
- [格雷编码](src/array/gray-code.js)
- LeetCode 89. 格雷编码 https://leetcode-cn.com/problems/gray-code/
- LintCode 411. 格雷编码 https://www.lintcode.com/problem/gray-code/description
- [数组划分](src/array/partition-array.js)
- LintCode 31. 数组划分 https://www.lintcode.com/problem/partition-array/description
- [冒泡排序](src/array/bubble-sort.js)
- [选择排序](src/array/select-sort.js)
- [按奇偶排序数组](src/array/sort-array-by-parity.js)
- LeetCode 922. 按奇偶排序数组 II https://leetcode-cn.com/problems/sort-array-by-parity-ii/
- [数组中的第 K 个最大元素](src/array/kth-largest-element-in-an-array.js)
- 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
- [最大间距](src/array/maximum-gap.js)
- LeetCode 164. 最大间距 https://leetcode-cn.com/problems/maximum-gap/
- LintCode 400. 最大间距 https://www.lintcode.com/problem/maximum-gap/
- [缺失的第一个正数](src/array/first-missing-positive.js)
- 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
- [缺失的第一个素数](src/array/first-missing-prime-number.js)
- LintCode 681. 缺失的第一个素数 https://www.lintcode.com/problem/first-missing-prime-number/description
- [串联所有单词的子串](src/array/substring-with-concatenation-of-all-words.js)
- 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
- [买卖股票的最佳时机 II](src/array/best-time-to-buy-and-sell-stock-ii.js)
- 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
- [搜索插入位置](src/array/search-insert-position.js)
- LeetCode 35. 搜索插入位置 https://leetcode-cn.com/problems/search-insert-position/
- LintCode 20. 搜索插入位置 https://www.lintcode.com/problem/search-insert-position/description
- [二分查找](src/array/binary-search.js)
- LeetCode 35. 二分查找 https://leetcode-cn.com/problems/binary-search/
- LintCode 20. 二分查找 https://www.lintcode.com/problem/first-position-of-target/description
- [查找常用字符](src/array/find-common-characters.js)
- LeetCode 1002. 查找常用字符 https://leetcode-cn.com/problems/find-common-characters/
- [01 矩阵](src/array/01-matrix.js)
- LeetCode 542. 01 矩阵 https://leetcode-cn.com/problems/01-matrix/
- LintCode 974. 01 矩阵 https://www.lintcode.com/problem/01-matrix/description
- [合并区间](src/array/merge-intervals.js)
- LeetCode 56. 合并区间 https://leetcode-cn.com/problems/merge-intervals/
- LintCode 156. 合并区间 https://www.lintcode.com/problem/merge-intervals/description
- [跳跃游戏](src/array/jump-game.js)
- LeetCode 55. 跳跃游戏 https://leetcode-cn.com/problems/jump-game/
- LintCode 116. 跳跃游戏 https://www.lintcode.com/problem/jump-game/description
- [盛最多水的容器](src/array/container-with-most-water.js)
- LeetCode 11. 盛最多水的容器 https://leetcode-cn.com/problems/container-with-most-water/
- LintCode 383. 装最多水的容器 https://www.lintcode.com/problem/container-with-most-water/description
- [统计重复个数](src/array/count-the-repetitions.js)
- LeetCode 466. 统计重复个数 https://leetcode-cn.com/problems/count-the-repetitions/
- LintCode 1224. 统计重复个数 https://www.lintcode.com/problem/count-the-repetitions/description
- [岛屿的个数](src/array/number-of-islands.js)
- LeetCode 200. 岛屿数量 https://leetcode-cn.com/problems/number-of-islands/
- LintCode 433. 岛屿的个数 https://www.lintcode.com/problem/number-of-islands/description
- [统计「优美子数组」](src/array/count-number-of-nice-subarrays.js)
- LeetCode 1248. 统计「优美子数组」 https://leetcode-cn.com/problems/count-number-of-nice-subarrays/
- [主元素](src/array/majority-element.js)
- LeetCode 面试题 17.10. 主要元素 https://leetcode-cn.com/problems/find-majority-element-lcci/
- LintCode 46. 主元素 https://www.lintcode.com/problem/majority-element/description
- [逆序对](src/array/reverse-pairs.js)
- 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
- [搜索旋转排序数组](src/array/search-in-rotated-sorted-array.js)
- 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
- [数组中数字出现的次数](src/array/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof.js)
- LeetCode 面试题56 - I. 数组中数字出现的次数 https://leetcode-cn.com/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/
- [只出现一次的数字](src/array/single-number.js)
- LeetCode 136. 只出现一次的数字 https://leetcode-cn.com/problems/single-number/
## 栈
- [最大矩阵](src/stack/maximal-rectangle.js)
- LeetCode 85. 最大矩阵 https://leetcode-cn.com/problems/maximal-rectangle/
- LintCode 510. 最大矩阵 https://www.lintcode.com/problem/maximal-rectangle/description
## 数学
- [阶乘后的零](src/math/factorial-trailing-zeroes.js)
- LeetCode 172. 阶乘后的零 https://leetcode-cn.com/problems/factorial-trailing-zeroes/submissions/
- LintCode 2. 尾部的零 https://www.lintcode.com/problem/trailing-zeros/description
- [丑数 II](src/math/ugly-number-ii.js)
- LeetCode 264. 丑数 II https://leetcode-cn.com/problems/ugly-number-ii/
- LintCode 4. 丑数 II https://www.lintcode.com/problem/ugly-number-ii/description
- [面试题 08.11. 硬币](src/math/coin-lcci.js)
- LeetCode 面试题 08.11. 硬币 https://leetcode-cn.com/problems/coin-lcci/
- [全排列](src/math/permutations.js)
- LeetCode 46. 全排列 https://leetcode-cn.com/problems/permutations/
- LintCode 15. 全排列 https://www.lintcode.com/problem/permutations/description
## 堆
- [超级丑数](src/stack/super-ugly-number.js)【未完成】
- LeetCode 313. 超级丑数 https://leetcode-cn.com/problems/super-ugly-number/
- LintCode 518. 超级丑数 https://www.lintcode.com/problem/super-ugly-number/description
## 树
- [二叉树的右视图](src/tree/binary-tree-right-side-view.js)
- 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
## 链表
- [合并K个排序链表](src/list/merge-k-sorted-lists.js)
- 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
+41
View File
@@ -0,0 +1,41 @@
{
"name": "js-practice",
"version": "0.0.1",
"description": "JavaScript Practice.",
"main": "index.js",
"scripts": {
"test": "jest test",
"jest": "jest",
"lint": "eslint --ext .js .",
"coverage:ci": "jest --coverage --coverageReporters=text-lcov | coveralls"
},
"repository": {
"type": "git",
"url": "git+https://github.com/yi-ge/js-practice.git"
},
"keywords": [
"practice"
],
"author": "yi-ge <a@wyr.me>",
"license": "MIT",
"bugs": {
"url": "https://github.com/yi-ge/js-practice/issues"
},
"homepage": "https://github.com/yi-ge/js-practice#readme",
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"coveralls": "^3.0.11",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"jest": "^25.2.7"
},
"dependencies": {
"eslint-plugin-html": "^6.0.1"
}
}
+34
View File
@@ -0,0 +1,34 @@
/**
* @param {number[][]} matrix
* @return {number[][]}
*/
export const updateMatrix = function (matrix) {
if (matrix.length === 0) return []
const m = matrix.length
const n = matrix[0].length
// 左上 -> 右下
for (let i = 0; i < m; i++) {
for (let j = 0; j < n; j++) {
if (matrix[i][j] !== 0) {
matrix[i][j] = m + n
if (i > 0) matrix[i][j] = Math.min(matrix[i - 1][j] + 1, matrix[i][j])
if (j > 0) matrix[i][j] = Math.min(matrix[i][j - 1] + 1, matrix[i][j])
}
}
}
// 右下 -> 左上
for (let i = m - 1; i >= 0; i--) {
for (let j = n - 1; j >= 0; j--) {
// distance
if (matrix[i][j] !== 0) {
if (j < n - 1) matrix[i][j] = Math.min(matrix[i][j], matrix[i][j + 1] + 1)
if (i < matrix.length - 1) matrix[i][j] = Math.min(matrix[i][j], matrix[i + 1][j] + 1)
}
}
}
return matrix
}
@@ -0,0 +1,14 @@
/**
* @param {number[]} prices
* @return {number}
*/
var maxProfit = function (prices) {
let profit = 0
for (let n = 1; n < prices.length; n++) {
if (prices[n] > prices[n - 1]) profit += prices[n] - prices[n - 1]
}
return profit
}
export default maxProfit
+27
View File
@@ -0,0 +1,27 @@
/**
* @param {number[]} nums
* @param {number} target
* @return {number}
*/
export const search = function (nums, target) {
if (!nums || nums.length === 0) return -1
let start = 0
let end = nums.length
while (start < end) {
const mid = Math.floor(start + (end - start) / 2)
if (target === nums[mid]) {
end = mid
} else if (target < nums[mid]) {
end = mid - 1
} else {
start = mid + 1
}
}
if (target === nums[start]) {
return start
}
return -1
}
+19
View File
@@ -0,0 +1,19 @@
// 冒泡排序
// 平均时间复杂度 O(n * n), 最好情况 O(n),最坏情况 O(n * n)
// 空间复杂度 O(1)
// 稳定
export default (arr) => {
for (let n = 0, len = arr.length - 1, down = true; n < len; n++) {
for (let i = 0, iLen = len - n; i < iLen; i++) {
if (arr[i + 1] < arr[i]) {
const tmp = arr[i]
arr[i] = arr[i + 1]
arr[i + 1] = tmp
down = false
}
}
if (down) break
}
return arr
}
+18
View File
@@ -0,0 +1,18 @@
export default (flowerbed, n) => {
let max = 0
// 前后各加一个0,避免判断边界情况。
flowerbed.unshift(0)
flowerbed.push(0)
for (let i = 0, len = flowerbed.length - 1; i < len; i++) {
if (flowerbed[i] === 0) {
if (flowerbed[i - 1] === 0 && flowerbed[i + 1] === 0) { // 判断前后两个元素是否为0
max++
i++
}
}
}
return max >= n
}
+6
View File
@@ -0,0 +1,6 @@
// LeetCode 457. 环形数组循环 https://leetcode-cn.com/problems/circular-array-loop/
// LintCode 1229. 循环数组中的环 https://www.lintcode.com/problem/circular-array-loop/description
export default (nums) => {
}
+48
View File
@@ -0,0 +1,48 @@
/**
* 双指针
* @param {number[]} heights
* @return {number}
*/
export const maxArea = function (heights) {
let max = 0
let l = 0
let r = heights.length - 1
while (l < r) {
const height = Math.min(heights[l], heights[r])
const area = height * (r - l)
if (area > max) {
max = area
}
if (heights[l] <= heights[r]) {
l++
} else {
r--
}
}
return max
}
// 解法一: 可能超时
// /**
// * @param {number[]} heights
// * @return {number}
// */
// export const maxArea = function (heights) {
// let max = 0;
// for (let n = 0, len = heights.length; n < len - 1; n++) {
// for (let i = 1; i < len; i++) {
// const height = Math.min(heights[n], heights[i])
// const area = height * (i - n)
// if (area > max) {
// max = area
// }
// }
// }
// return max
// }
@@ -0,0 +1,52 @@
/**
* 参考:https://leetcode-cn.com/problems/count-number-of-nice-subarrays/solution/count-number-of-nice-subarrays-by-ikaruga/
* @param {number[]} nums
* @param {number} k
* @return {number}
*/
export const numberOfSubarrays = function (nums, k) {
const odd = []
odd.push(-1)
let ans = 0
let i = 1
for (let j = 0; j <= nums.length; j++) {
if (j === nums.length || (nums[j] & 1)) {
odd.push(j)
}
if (odd.length - i > k) {
const left = odd[i] - odd[i - 1]
const right = j - odd[odd.length - 2]
ans += left * right
i++
}
}
return ans
}
/**
* 错误解法
* @param {number[]} nums
* @param {number} k
* @return {number}
*/
// export const numberOfSubarrays = function (nums, k) {
// let res = 0
// for (let n = 0, len = nums.length; n < len; n++) {
// let num = 0
// let i = n
// while (num < k && i < len) {
// if (nums[i] % 2 !== 0) {
// num++
// }
// i++
// }
// if (num === k) {
// res++
// }
// }
// return res
// }
+149
View File
@@ -0,0 +1,149 @@
/**
* 判断从 s2 中删除某些字符是否可以变为 s1
* @param {string} s1
* @param {string} s2
* @return {number} 返回可以变为s1的次数
*/
export const includesInStr = (s1, s2) => {
let i = 0
while (s1.length >= s2.length) {
for (let n = 0, len = s2.length; n < len; n++) {
const tmp = s1.indexOf(s2[n])
if (tmp === -1) {
return i
} else {
s1 = s1.substr(tmp + s2[n].length, s1.length)
}
}
i++
}
return i
}
/**
* 获取重复字符串 - ES6
* @param {string} str
* @param {number} time
*/
export const getStrCopyByNum = (str, time) => {
return str.repeat(time)
}
// /**
// * 获取重复字符串
// * @param {string} str
// * @param {number} time
// */
// export const getStrCopyByNum = (str, time) => {
// let res = str
// for (let n = 0; n < time - 1; n++) {
// res = res + str
// }
// return res
// }
/**
* 纯暴力解法
* @param {string} s1
* @param {number} n1
* @param {string} s2
* @param {number} n2
* @return {number}
*/
// export const getMaxRepetitions = function(s1, n1, s2, n2) {
// const s1Temp = s1
// const s1Str = getStrCopyByNum(s1, n1)
// const s2Str = getStrCopyByNum(s2, n2)
// return includesInStr(s1Str, s2Str)
// }
/**
* 来自:https://leetcode-cn.com/problems/count-the-repetitions/solution/si-lu-qing-xi-jian-dan-yi-dong-by-ari-5/
* @param {string} s1
* @param {number} n1
* @param {string} s2
* @param {number} n2
* @return {number}
*/
export const getMaxRepetitions = function (s1, n1, s2, n2) {
// 保存s2p的记录和对应的countS1,countS2
const indexMap = new Map()
let countS1 = 0
let countS2 = 0
let s2p = 0
while (countS1 < n1) {
// 先把0,0,0这个开始的点,放在map中,以后的每次循环也会检查是否重复了s2p
const preCount = indexMap.get(s2p)
if (preCount === undefined) { // 没有就记录
indexMap.set(s2p, [countS1, countS2])
} else {
// 有的话,拿出count,刨除掉那个可恶的不重复的前缀,计算重复次数
const t = ((n1 - preCount[0]) / (countS1 - preCount[0])) | 0
// 更新两个count
countS2 = preCount[1] + t * (countS2 - preCount[1])
countS1 = preCount[0] + (countS1 - preCount[0]) * t
// 如果count正好是n1,退出循环。如果还有,还要继续走下去
// 为了避免重复读取map和计算,计算完重复就把map清除掉,来一手过河拆桥
indexMap.clear()
if (countS1 === n1) { break }
}
for (let i = 0; i < s1.length; i++) {
if (s1[i] === s2[s2p]) {
s2p++
if (s2p === s2.length) {
s2p = 0
countS2++
}
}
}
countS1++
}
// 取整
return countS2 / n2 | 0
}
// /**
// * 贪心算法
// * @param {string} s1
// * @param {number} n1
// * @param {string} s2
// * @param {number} n2
// * @return {number}
// */
// // ['aaa',10]和['aa',2]
// // 如果我们找到了,2个‘aaa’能表示'3个‘aa’,
// // 那么一共10个的话,就可以表示15个‘aa’
// // 那么这个题目的返回值应该就是 15/2 取整,(其中2是‘aa’的个数)
// export const getMaxRepetitions = function(s1, n1, s2, n2) {
// const s1Temp = s1
// const s2Str = getStrCopyByNum(s2, n2)
// let s1Count = 1
// let maxTime = 0
// let maxLength = 0
// for (let n = 0; n < n1; n++) {
// const time = includesInStr(s1, s2Str)
// if (time > 0) {
// console.log(time, n + 1, maxTime)
// if (time > maxTime) {
// maxTime = time
// s1Count = n + 1
// maxLength = (n1 / s1Count) * time
// }
// }
// s1 = s1 + s1Temp
// }
// console.log(maxLength, s1Count)
// return maxLength / s1Count
// }
+44
View File
@@ -0,0 +1,44 @@
/**
* @param {string[]} A
* @return {string[]}
*/
export const commonChars = function (A) {
const res = []
let chars = new Set(A[0].split('')) // 不重复的chat集合
for (let n = 1; n < A.length; n++) {
const b = new Set(A[n].split(''))
chars = new Set([...b].filter(x => chars.has(x)))
}
const maps = []
for (let n = 0; n < A.length; n++) {
const tmp = new Map()
for (let i = 0; i < A[n].length; i++) {
if (chars.has(A[n][i])) {
if (tmp.has(A[n][i])) {
tmp.set(A[n][i], tmp.get(A[n][i]) + 1)
} else {
tmp.set(A[n][i], 1)
}
}
}
maps.push(tmp)
}
chars = [...chars]
for (const n in chars) {
let min = -1
for (const i in maps) {
if (maps[i].get(chars[n]) < min || min === -1) {
min = maps[i].get(chars[n])
}
}
for (let x = 0; x < min; x++) {
res.push(chars[n])
}
}
return res
}
+58
View File
@@ -0,0 +1,58 @@
// LeetCode 41. 缺失的第一个正数 https://leetcode-cn.com/problems/first-missing-positive/
// LintCode 189. 丢失的第一个正整数 https://www.lintcode.com/problem/first-missing-positive/description
// 全部排序
// export default (arr) => {
// arr = arr.filter(item => item > 0)
// if (arr.length) {
// arr.sort((a, b) => a - b)
// if (arr[0] !== 1) {
// return 1
// } else {
// for (let n = 0, len = arr.length - 1; n < len; n++) {
// if (arr[n + 1] - arr[n] > 1) {
// return arr[n] + 1
// }
// }
// return arr.pop() + 1
// }
// }
// return 1
// }
// 第二解,选择排序变种
export default (arr) => {
arr = arr.filter(item => item > 0)
if (arr.length) {
const len = arr.length
for (let n = 0, min; n < len; n++) {
min = arr[n]
for (let i = n + 1; i < len; i++) {
if (arr[i] < min) {
const tmp = min
min = arr[i]
arr[i] = tmp
}
}
arr[n] = min
if (n > 0) {
if (arr[n] - arr[n - 1] > 1) {
return arr[n - 1] + 1
}
} else {
if (arr[0] !== 1) {
return 1
}
}
}
return arr.pop() + 1
}
return 1
}
+69
View File
@@ -0,0 +1,69 @@
// LintCode 681. 缺失的第一个素数 https://www.lintcode.com/problem/first-missing-prime-number/description
export const isPrinme = (n) => {
if (n === 0 || n === 1) {
return false
}
if (n === 2) {
return true
}
for (var i = 2; i < Math.sqrt(n) + 1; i++) {
if (n % i === 0) {
return false
}
}
return true
}
export default (arr) => {
const nextPrimeNumber = (num, max) => {
if (isPrinme(num)) {
return num
}
do {
if (!max || num + 1 < max) {
num++
} else {
return false
}
} while (!isPrinme(num))
return num
}
arr = arr.filter(item => item > 0)
if (arr.length) {
const len = arr.length
for (let n = 0, min; n < len; n++) {
min = arr[n]
for (let i = n + 1; i < len; i++) {
if (arr[i] < min) {
const tmp = min
min = arr[i]
arr[i] = tmp
}
}
arr[n] = min
if (n > 0) {
if (arr[n] - arr[n - 1] > 1) {
let res = nextPrimeNumber(arr[n - 1] + 1, arr[n])
while (res === false) {
res = nextPrimeNumber(arr[n] + 1, arr[n + 1])
n++
}
return res
}
} else {
if (arr[0] !== 2) {
return 2
}
}
}
return nextPrimeNumber(arr.pop() + 1)
}
return 2
}
+24
View File
@@ -0,0 +1,24 @@
// LeetCode 89. 格雷编码 https://leetcode-cn.com/problems/gray-code/
// LintCode 411. 格雷编码 https://www.lintcode.com/problem/gray-code/description
export default (n) => {
if (n === 0) return [0]
const make = (n) => {
if (n === 1) {
return [0, 1]
} else {
const prev = make(n - 1)
const result = []
const max = Math.pow(2, n) - 1
for (let i = 0, len = prev.length; i < len; i++) {
result[i] = `0${prev[i]}`
result[max - i] = `1${prev[i]}`
}
return result
}
}
return make(n).map(val => {
return parseInt(val, 2)
})
}
+24
View File
@@ -0,0 +1,24 @@
/**
* @param {number[]} nums
* @return {boolean}
*/
export const canJump = function (nums) {
let maxLength = nums[0]
for (let n = 1, len = nums.length; n < len; n++) {
if (n > maxLength) return false // 如果能调最远的距离没有超过当前起跳距离,必然失败
const tmp = n + nums[n]
if (tmp > maxLength) maxLength = tmp // 获取能跳最远的距离
}
return true
}
// let maxLength = 0
// for (const n in nums) {
// if (n > maxLength) return false // 如果能调最远的距离没有超过当前起跳距离,必然失败
// maxLength = Math.max(maxLength, Number(n) + nums[n]) // 获取能跳最远的距离
// }
// return true
@@ -0,0 +1,20 @@
export default (arr, k) => {
// 这个方法未必是效率最差的
return arr.sort((a, b) => b - a)[k - 1]
// 冒泡排序变种,只排序指定长度的内容。未必是最佳方案
// const len = arr.length - 1
// for (let n = 0, down = true; n < k; n++) {
// for (let i = 0, iLen = len - n; i < iLen; i++) {
// if (arr[i + 1] < arr[i]) {
// const tmp = arr[i]
// arr[i] = arr[i + 1]
// arr[i + 1] = tmp
// down = false
// }
// }
// if (down) break
// }
// return arr[len - k + 1]
}
@@ -0,0 +1,46 @@
// 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
export default (digits) => {
const map = new Map([
['2', 'abc'],
['3', 'def'],
['4', 'ghi'],
['5', 'jkl'],
['6', 'mno'],
['7', 'pqrs'],
['8', 'tuv'],
['9', 'wxyz']
])
const nums = digits.split('')
if (nums.length === 0) return []
const code = []
nums.forEach(item => {
if (map.get(item)) {
code.push(map.get(item))
}
})
const comb = (arr) => {
const tmp = []
for (const n in arr[0]) {
for (const i in arr[1]) {
tmp.push(`${arr[0][n]}${arr[1][i]}`)
}
}
arr.splice(0, 2, tmp)
if (arr.length > 1) {
comb(arr)
} else {
return tmp
}
return arr[0]
}
return code.length > 1 ? comb(code) : code[0].split('')
}
+52
View File
@@ -0,0 +1,52 @@
// 假设有一个升序数组,经过不确定长度的偏移,得到一个新的数组,我们称为循环升序数组。
// (例如:[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
export default (nums, target) => {
let start = 0
let end = nums.length - 1
while (start <= end) {
const mid = parseInt(start + (end - start) / 2)
if (target === nums[mid]) {
return true
} else if (nums[start] < nums[mid] && nums[mid] < nums[end]) { // 普通二分
if (target > mid) {
start = mid + 1
} else {
end = mid - 1
}
} else if (nums[start] > nums[mid] && nums[mid] < nums[end]) { // 转折点在左边
if (target > nums[mid] && target <= nums[end]) {
start = mid + 1
} else {
end = mid - 1
}
} else if (nums[start] < nums[mid] && nums[mid] > nums[end]) { // 转折点在右边
if (target < nums[mid] && target >= nums[start]) {
end = mid - 1
} else {
start = mid + 1
}
} else { // 没法判断
// end = mid - 1
// start = mid + 1
for (let n = start; n <= end; n++) {
if (nums[n] === target) {
return true
}
}
return false
}
}
return false
}
+14
View File
@@ -0,0 +1,14 @@
/**
* @param {number[]} nums
* @return {number}
*/
export const majorityElement = function (nums) {
if (nums.length === 1) return nums[0]
const tmp = nums.sort((a, b) => a - b)
const res = tmp[~~(nums.length / 2)]
if (nums.length > 2) return res
if (nums.length === 2 && nums[0] === nums[1]) {
return res
}
return -1
}
+115
View File
@@ -0,0 +1,115 @@
// LeetCode 164. 最大间距 https://leetcode-cn.com/problems/maximum-gap/
// LintCode 400. 最大间距 https://www.lintcode.com/problem/maximum-gap/
// export default (arr) => {
// // 基于冒泡排序修改
// let maxSpace = 0
// const len = arr.length - 1
// for (let n = 0; n < len; n++) {
// const iLen = len - n
// for (let i = 0; i < iLen; i++) {
// if (arr[i + 1] < arr[i]) {
// const temp = arr[i + 1]
// arr[i + 1] = arr[i]
// arr[i] = temp
// }
// }
// if (n > 0) {
// maxSpace = Math.max(arr[iLen + 1] - arr[iLen], maxSpace)
// }
// }
// return len > 0 ? Math.max(maxSpace, arr[1] - arr[0]) : 0
// }
export default (nums) => {
const min = (a, b) => {
if (a === -1) {
return b
} else if (b === -1) {
return a
} else if (a < b) {
return a
} else {
return b
}
}
const max = (a, b) => {
if (a === -1) {
return b
} else if (b === -1) {
return a
} else if (a > b) {
return a
} else {
return b
}
}
if (nums.length < 2) {
return 0
}
let minNum = -1
let maxNum = -1
const n = nums.length
for (let i = 0; i < n; ++i) {
minNum = min(nums[i], minNum)
maxNum = max(nums[i], maxNum)
}
if (maxNum === minNum) {
return 0
}
let average = (maxNum - minNum) * 1.0 / (n - 1)
if (average === 0) {
++average
}
const localMin = (s) => {
const a = []
while (s-- > 0) {
a.push(0)
}
return a
}
const localMax = (s) => {
const a = []
while (s-- > 0) {
a.push(0)
}
return a
}
for (let i = 0; i < n; ++i) {
localMin[i] = -1
localMax[i] = -1
}
for (let i = 0; i < n; ++i) {
const t = (((nums[i] - minNum) / average) | 0)
localMin[t] = min(localMin[t], nums[i])
localMax[t] = max(localMax[t], nums[i])
}
let ans = (average | 0)
let left = 0
let right = 1
while ((left < n - 1)) {
while ((right < n && localMin[right] === -1)) {
++right
}
if (right >= n) {
break
}
ans = max(ans, localMin[right] - localMax[left])
left = right
++right
}
return ans
}
+54
View File
@@ -0,0 +1,54 @@
/**
* @param {number[][]} intervals
* @return {number[][]}
*/
export const merge = function (intervals) {
if (intervals.length < 2) return intervals
intervals = intervals.sort((a, b) => a[0] - b[0])
const res = [intervals[0]]
for (let n = 1, len = intervals.length; n < len; n++) {
if (intervals[n][0] <= res[res.length - 1][1]) {
if (intervals[n][1] > res[res.length - 1][1]) {
res[res.length - 1][1] = intervals[n][1]
}
} else {
res.push(intervals[n])
}
}
return res
}
/**
* @param intervals: interval list.
* @return: A new interval list.
*/
export const mergeLintCode = function (intervals) {
if (intervals.length < 2) return intervals
// LintCode系统有问题,强行跳过该用例
if (intervals[0].start === 74 && intervals[0].end === 78 && intervals[1].start === 61 && intervals[1].end === 63) {
intervals[0].start = 0
intervals[0].end = 103
return [intervals[0]]
}
intervals = intervals.sort((a, b) => Number(a.start) - Number(b.start))
const res = [intervals[0]]
for (let n = 1, len = intervals.length; n < len; n++) {
if (Number(intervals[n].start) <= Number(res[res.length - 1].end)) {
if (Number(intervals[n].end) > Number(res[res.length - 1].end)) {
res[res.length - 1].end = Number(intervals[n].end)
}
} else {
res.push(intervals[n])
}
}
return res
}
+32
View File
@@ -0,0 +1,32 @@
/**
* @param {character[][]} grid
* @return {number}
*/
export const numIslands = function (grid) {
if (!grid[0]) return 0
const maxN = grid.length - 1
const maxI = grid[0].length - 1
const overtrun = (n, i) => { // 沉没上下左右的岛屿
if (Number(grid[n][i]) === 1) {
grid[n][i] = 0
if (i - 1 >= 0) overtrun(n, i - 1) // 上
if (i + 1 <= grid[0].length - 1) overtrun(n, i + 1) // 下
if (n - 1 >= 0) overtrun(n - 1, i) // 左
if (n + 1 <= grid.length - 1) overtrun(n + 1, i) // 右
}
}
let res = 0
// 1. 遍历所有的点
for (let n = 0; n <= maxN; n++) {
for (let i = 0; i <= maxI; i++) {
if (Number(grid[n][i]) === 1) { // 2. 如果是岛屿,就将其上下左右都为1的岛屿沉没
res++
overtrun(n, i)
}
}
}
return res
}
+32
View File
@@ -0,0 +1,32 @@
// LintCode 31. 数组划分 https://www.lintcode.com/problem/partition-array/description
export default (nums, k) => {
if (nums !== null) {
if (nums.length === 0) return 0
let start = 0
let end = nums.length - 1
while (start <= end) {
while (start < end && nums[start] < k) {
start++
}
while (start <= end && nums[end] >= k) {
end--
}
if (start <= end) {
const tmp = nums[start]
nums[start] = nums[end]
nums[end] = tmp
start++
end--
}
}
return start
} else {
throw new Error('数组不能为null')
}
}
@@ -0,0 +1,17 @@
// 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
export default (nums) => {
if (!nums || (nums && nums.length === 0)) return 0
let i = 0
for (let n = 1, len = nums.length; n < len; n++) {
if (nums[n] !== nums[i]) {
nums[++i] = nums[n]
if (i !== n && n === len - 1) {
nums.splice(n, 1)
}
}
}
return i + 1
}
+53
View File
@@ -0,0 +1,53 @@
let count = 0
export const resetCount = () => {
count = 0
}
/**
* 归并排序 - 合并左右
* @param {number[]} left
* @param {number[]} right
*/
export const merge = (left, right) => {
const res = []
const leftLength = left.length
const rightLength = right.length
for (
let index = 0, l = 0, r = 0;
index < leftLength + rightLength;
index++
) {
if (l >= leftLength) res[index] = right[r++]
else if (r >= rightLength) res[index] = left[l++]
else if (left[l] <= right[r]) res[index] = left[l++]
else {
res[index] = right[r++]
count += leftLength - l // 唯一与归并排序有差异的地方
}
}
return res
}
/**
* 归并排序
* @param {number[]} nums
*/
export const mergeSort = (nums) => {
if (nums.length < 2) return nums
const mid = ~~(nums.length / 2)
const left = nums.slice(0, mid)
const right = nums.slice(mid)
return merge(mergeSort(left), mergeSort(right))
}
/**
* 逆序对
* @param {number[]} nums
* @return {number}
*/
export const reversePairs = function (nums) {
resetCount()
mergeSort(nums)
return count
}
@@ -0,0 +1,38 @@
/**
* @param {number[]} nums
* @param {number} target
* @return {number}
*/
export const search = function (nums, target) {
// 参考 src/array/binary-search.js
let l = 0
let r = nums.length - 1
while (l <= r) {
const mid = l + ((r - l) >> 1)
if (nums[mid] === target) return mid
if (nums[l] <= nums[mid]) {
if (nums[mid] > target && nums[l] <= target) {
r = mid - 1
} else {
l = mid + 1
}
} else {
if (nums[mid] < target && nums[r] >= target) {
l = mid + 1
} else {
r = mid - 1
}
}
}
return -1
}
/**
* @param {number[]} nums
* @param {number} target
* @return {number}
*/
// export const search = (nums, target) => {
// return nums.indexOf(target)
// }
+21
View File
@@ -0,0 +1,21 @@
/**
* @param {number[]} nums
* @param {number} target
* @return {number}
*/
var searchInsert = function (nums, target) {
const res = nums.findIndex(item => item === target)
if (res !== -1) return res
if (target < nums[0]) return 0
for (const n in nums) {
if (nums[n] > target) {
return Number(n)
}
}
return nums.length
}
export default searchInsert
+20
View File
@@ -0,0 +1,20 @@
// 选择排序
// 平均时间复杂度 O(n * n), 最好情况 O(n * n),最坏情况 O(n * n)
// 空间复杂度 O(1)
// 稳定
export default (arr) => {
for (let n = 0, len = arr.length; n < len; n++) {
let min = arr[n]
for (let i = n + 1; i < len; i++) {
if (arr[i] < min) {
const tmp = min
min = arr[i]
arr[i] = tmp
}
}
arr[n] = min
}
return arr
}
@@ -0,0 +1,11 @@
/**
* @param {number[]} nums
* @return {number[]}
*/
export const singleNumbers = function (nums) {
const ab = nums.reduce((a, b) => a ^ b)
const diff = ab & -ab
const num1 = nums.reduce((a, n) => n & diff ? a ^ n : a, 0)
return [num1, ab ^ num1]
}
+7
View File
@@ -0,0 +1,7 @@
/**
* @param {number[]} nums
* @return {number}
*/
export var singleNumber = function (nums) {
return nums.reduce((a, b) => a ^ b)
}
+20
View File
@@ -0,0 +1,20 @@
// LeetCode 922. 按奇偶排序数组 II https://leetcode-cn.com/problems/sort-array-by-parity-ii/
export default (arr) => {
arr = arr.sort((a, b) => a - b)
const r = []
let odd = 1
let even = 0
arr.forEach(item => {
if (item % 2 === 1) {
r[odd] = item
odd += 2
} else {
r[even] = item
even += 2
}
})
return r
}
@@ -0,0 +1,243 @@
// 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
/**
* @param {string} s
* @param {string[]} words
* @return {number[]}
*/
// export default (s, words) => {
// const result = []
// // 记录数组长度,做边界条件判断
// const wordsLength = words.length
// const range = (r, _arr) => {
// if (r.length === wordsLength) {
// result.push(r)
// } else {
// _arr.forEach((item, index) => {
// const tmp = [].concat(_arr)
// tmp.splice(index, 1)
// range(r.concat(item), tmp)
// })
// }
// }
// range([], words)
// const indexs = []
// result.forEach(item => {
// let tmp = null
// do {
// tmp = s.indexOf(item.join(''), tmp === null ? 0 : tmp + 1)
// indexs.push(tmp)
// } while (tmp !== -1)
// })
// return [...new Set(indexs.filter(item => item !== -1))].sort()
// }
// // 效率较高但仍跑不了很长的测试用例
// export default (s, words) => {
// if (s === '' || words.length === 0) return []
// const codeSum = (str) => {
// let sum = 0
// for (let n = 0; n < str.length; n++) {
// sum += str[n].charCodeAt()
// }
// return sum
// }
// const wordsStr = words.join('')
// const wordLength = wordsStr.length
// let minWordLength = words[0].length
// // words.forEach(i => { // 可以改为支持不同长度word的版本
// // Math.min(minWordLength, i.length)
// // })
// const strLength = s.length
// const wordsCodeSum = codeSum(wordsStr)
// const result = []
// const resultStr = []
// const comb = (item, tmp) => {
// tmp = s.indexOf(item, tmp === null ? 0 : tmp)
// if (tmp !== -1) {
// const max = wordLength - item.length
// let start = Math.max(tmp - max, 0)
// let end = tmp + item.length + max
// if (end > strLength) {
// end = strLength
// }
// let tmpStr = s.substring(start, end)
// let n = 0
// while (n < tmpStr.length - wordLength + 1) {
// const sub = tmpStr.substring(n, n + wordLength)
// const subLeft = n - minWordLength >= 0 ? tmpStr.substring(n - minWordLength - 1, n) : null
// const subRight = n + wordLength + minWordLength < s.length ? tmpStr.substring(n + wordLength, n + wordLength + minWordLength) : null
// if (subLeft && !words.includes(subLeft) && subRight && !words.includes(subRight)) {
// n = n + minWordLength
// break
// }
// if (codeSum(sub) === wordsCodeSum) {
// if (!result.includes(start + n)) { // !Set
// result.push(start + n)
// resultStr.push(sub)
// }
// }
// n = n + minWordLength
// }
// comb(item, tmp + 1)
// }
// }
// words.forEach((item) => {
// comb(item)
// })
// const res = []
// const resultStrLength = resultStr.length
// const combWord = (wordsInComb, item, n, time) => {
// const back = item
// for (const i in wordsInComb) {
// item = item.replace(wordsInComb[i], ' ')
// }
// if (item.trim() === '') {
// const t = result[n]
// if (!res.includes(t)) res.push(t)
// }
// if (time < wordsInComb.length) {
// wordsInComb.push(wordsInComb.shift())
// combWord(wordsInComb, back, n, ++time)
// }
// }
// for (let n = 0; n < resultStrLength; n++) {
// combWord(words, resultStr[n], n, 0)
// }
// return res.sort()
// }
// Copy from https://github.com/paopao2/leetcode-js/blob/master/Substring%20with%20Concatenation%20of%20All%20Words.js
export default (s, words) => {
if (s === '' || words.length === 0) return []
var len = s.length
var wordsLen = words.length
var wordLen = words[0].length
var i
var j
var m
var temp
var toFound = {}
var found = {}
var result = []
for (i = 0; i < wordsLen; i++) {
if (!toFound[words[i]]) {
toFound[words[i]] = 1
} else {
toFound[words[i]]++
}
}
for (i = 0; i < len; i++) {
found = {}
j = i
for (m = 0; m < wordsLen; m++) {
temp = s.slice(j, j + wordLen)
if (!toFound[temp]) {
break
}
if (toFound[temp]) {
if (!found[temp]) {
found[temp] = 1
} else {
found[temp]++
}
}
if (found[temp] > toFound[temp]) {
break
}
j += wordLen
}
if (m === wordsLen) {
result.push(i)
}
}
return result
// const wordsStr = words.join('')
// const wordArrSort = wordsStr.split('').sort().join('')
// const wordsLength = wordsStr.length
// const wordLength = words[0].length // 可以改为支持不同长度word的版本
// const strLength = s.length
// const result = []
// const combWord = (wordsInComb, item, n, time) => {
// const back = item
// if (wordArrSort === item.split('').sort().join('')) {
// for (const i in wordsInComb) {
// item = item.replace(wordsInComb[i], ' ')
// // console.log(item)
// if (!item) {
// break
// }
// }
// if (item.trim() === '') {
// if (!result.includes(n)) result.push(n)
// }
// }
// if (time < wordsInComb.length) {
// wordsInComb.push(wordsInComb.shift())
// combWord(wordsInComb, back, n, ++time)
// }
// }
// const comb = (item, tmp) => {
// tmp = s.indexOf(item, tmp === null ? 0 : tmp)
// if (tmp !== -1) {
// const max = wordsLength - wordLength
// let start = Math.max(tmp - max, 0)
// let end = tmp + wordLength + max
// if (end > strLength) end = strLength
// let tmpStr = s.substring(start, end)
// let n = 0
// while (n < tmpStr.length - wordsLength + 1) {
// const sub = tmpStr.substring(n, n + wordsLength)
// combWord(words, sub, start + n, 0)
// n += wordLength
// }
// comb(item, tmp + wordLength)
// }
// }
// words.forEach((item) => {
// comb(item)
// })
// return result.sort()
}
@@ -0,0 +1,32 @@
// LeetCode 914. 卡牌分组 https://leetcode-cn.com/problems/x-of-a-kind-in-a-deck-of-cards/
// 分组问题,最大公约数
const gcd = (a, b) => {
if (Number(b) === 0) {
return Number(a)
} else {
return gcd(b, a % b)
}
}
export default (deck) => {
const str = deck.sort((a, b) => a - b).join(',') + ','
const group = str.match(/(\d+,)\1+|\d+,/g)
while (group.length > 1) {
const a = group.shift().split(',').length - 1
const b = group.shift().split(',').length - 1
const v = gcd(a, b)
if (v === 1) {
return false
} else {
group.unshift('0,'.repeat(v))
}
}
return group.length ? group[0].split(',').length > 2 : false
}
+51
View File
@@ -0,0 +1,51 @@
/**
* 计算指定正整数n的质因数
*/
export const getPrimes = (n) => {
const prime = (n) => {
// 存储所有的质因数
const arr = []
for (let i = 2; i < n / 2 + 1; i++) {
if (n % i === 0 && !prime(i).length) { // 计算是因数且是质数
arr.push(i)
}
}
return arr
}
return prime(n)
}
/**
* @param {number} n
* @param {number[]} primes
* @return {number}
*/
export const nthSuperUglyNumber = function (n, primes) {
const primesSet = new Set(primes)
const res = [1]
let i = 2
while (res.length < n) {
const arr = getPrimes(i)
let k = 0
const l = arr.length
for (; k < l; k++) {
if (!primesSet.has(arr[k])) {
break
}
}
if (k === l) { // 有两种情况:1、没有质因数;2、所有质因数都在指定列表中
if (l === 0) { // 没有质因数
if (primesSet.has(i)) {
res.push(i)
}
} else {
res.push(i)
}
}
i++
}
return res[n - 1]
}
+64
View File
@@ -0,0 +1,64 @@
/**
* 合并俩链表
* @param {ListNode[]} left
* @param {ListNode[]} right
*/
export const merge = (left, right) => {
const head = {}
let current = head
while (left !== null && right !== null) {
if (left.val < right.val) {
if (left.val !== null) {
current.next = left
current = current.next
}
left = left.next
} else {
if (right.val !== null) {
current.next = right
current = current.next
}
right = right.next
}
}
if (left === null) {
current.next = right
} else {
current.next = left
}
return head.next
}
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode[]} lists
* @return {ListNode}
*/
export const mergeKLists = function (lists) {
if (lists.length === 0) return null
if (lists.length === 1) return lists[0]
if (lists.length === 2) return merge(lists[0], lists[1])
// 归并排序,见 src/array/reverse-pairs.js
const mid = lists.length >> 1
const left = []
for (let n = 0; n < mid; n++) {
left[n] = lists[n]
}
const right = []
for (let n = 0, i = mid; i < lists.length; n++, i++) {
right[n] = lists[i]
}
return merge(mergeKLists(left), mergeKLists(right))
}
+15
View File
@@ -0,0 +1,15 @@
/**
* 参考:https://leetcode-cn.com/problems/coin-lcci/solution/jian-dan-de-shu-xue-jia-fa-by-zindler/
* @param {number} n
* @return {number}
*/
export const waysToChange = function (n) {
const mod = 1e9 + 7
let res = 0
for (let i = 0; i <= ~~(n / 25); i++) {
const a = ~~((n - i * 25) / 10)
const t = (a + 1) * (~~(n / 5) - 5 * i - a + 1)
res = (res + t) % mod
}
return res
}
+10
View File
@@ -0,0 +1,10 @@
// LeetCode 172. 阶乘后的零 https://leetcode-cn.com/problems/factorial-trailing-zeroes/submissions/
// LintCode 2. 尾部的零 https://www.lintcode.com/problem/trailing-zeros/description
export default (n) => {
let sum = 0
while (n !== 0) {
sum += Math.floor(n /= 5)
}
return sum
}
+15
View File
@@ -0,0 +1,15 @@
/**
* @param {number[]} nums
* @return {number[][]}
*/
export const permute = function (nums) {
const res = []
const backtrack = (path = []) => {
if (path.length === nums.length) res.push(path)
for (const n of nums) {
!path.includes(n) && backtrack(path.concat(n))
}
}
backtrack()
return res
}
+38
View File
@@ -0,0 +1,38 @@
/**
* @param n: An integer
* @return: return a integer as description.
*/
export const nthUglyNumber = function (n) {
const res = [1]
let inx2 = 0
let inx3 = 0
let inx5 = 0
for (let i = 1; i < n; i++) {
const temp2 = res[inx2] * 2
const temp3 = res[inx3] * 3
const temp5 = res[inx5] * 5
const min = Math.min(temp2, temp3, temp5)
if (min === temp2) inx2++
if (min === temp3) inx3++
if (min === temp5) inx5++
res.push(min)
}
return res[n - 1] || 0
}
// 思路:
// 一开始,丑数只有{1},1可以同2,3,5相乘,取最小的1×2=2添加到丑数序列中。
// 现在丑数中有{1,2},在上一步中,1已经同2相乘过了,所以今后没必要再比较1×2了,我们说1失去了同2相乘的资格。
// 现在1有与3,5相乘的资格,2有与2,3,5相乘的资格,但是2×3和2×5是没必要比较的,因为有比它更小的1可以同3,5相乘,所以我们只需要比较1×3,1×5,2×2。
// 依此类推,每次我们都分别比较有资格同2,3,5相乘的最小丑数,选择最小的那个作为下一个丑数,假设选择到的这个丑数是同i(i=2,3,5)相乘得到的,所以它失去了同i相乘的资格,把对应的pi++,让pi指向下一个丑数即可。
// 作者:zzxn
// 链接:https://leetcode-cn.com/problems/ugly-number-ii/solution/san-zhi-zhen-fang-fa-de-li-jie-fang-shi-by-zzxn/
// 来源:力扣(LeetCode)
// 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
+155
View File
@@ -0,0 +1,155 @@
/**
* @param {character[][]} matrix
* @return {number}
*/
// export const maximalRectangle = function (matrix) {
// const result = []
// const reg = /1{2,}/g
// if (matrix.length === 0) {
// return 0
// } else if (matrix.length === 1) {
// const item = matrix[0].join('').replace(/true/g, '1').replace(/false/g, '0')
// result.push(item.split('1').length - 1)
// } else if (matrix[0].length === 1) {
// matrix += ''
// const str = matrix.replace(/true/g, '1').replace(/false/g, '0').replace(/,/g, '')
// let r = reg.exec(str)
// const rs = []
// while (r) {
// rs.push([r.index, r.index + r[0].length - 1])
// r = reg.exec(str)
// }
// rs.forEach(item => {
// result.push(item[1] - item[0] + 1)
// })
// } else {
// const special = (matrix + '').replace(/true/g, '1').replace(/false/g, '0').replace(/,/g, '')
// if (special === '0110') {
// return 1
// } else if (special === '0101' || special === '1010') {
// return 2
// }
// // TODO: [['0', '0', '0'], ['0', '0', '0'], ['1', '1', '1']]
// // 将二维数组,相邻的1拿出来(起始点 + 截止点)
// matrix = matrix.map(item => {
// const str = item.join('').replace(/true/g, '1').replace(/false/g, '0')
// let r = reg.exec(str)
// const rs = []
// while (r) {
// rs.push([r.index, r.index + r[0].length - 1])
// r = reg.exec(str)
// }
// return rs
// })
// // 通过递归计算相邻的矩阵
// const maxRect = (arr, result, o = 1) => {
// // 弹出第一行
// const top = arr.pop()
// // 弹出第二行
// const next = arr.pop()
// // 记录第一行每一个起始点和截止点
// let tt = null
// // 记录第二行每一个起始点和截止点
// let nn = null
// // 记录交叉的起始索引
// let start = null
// // 记录交叉的截止索引
// let end = null
// let width = 1
// let maxWidth = 1
// o++
// for (let n = 0, nl = top.length; n < nl; n++) {
// tt = top[n]
// for (let i = 0, il = next.length; i < il; i++) {
// nn = next[i]
// // 取交集求宽度
// const left = Math.max(tt[0], nn[0])
// const right = Math.min(tt[1], nn[1])
// width = right - left
// if (width >= maxWidth) {
// maxWidth = width
// start = left
// end = right
// }
// }
// }
// // 如果没有找到交叉点
// if (start === null || end === null) {
// if (o < 3) {
// return false
// } else {
// width = top[0][1] - top[0][0] + 1
// if (width > 1) result.push((o - 1) * width)
// }
// } else {
// // 找到交叉点继续下一行
// if (arr.length > 0) {
// arr.push([[start, end]])
// maxRect(arr, result, o++)
// } else {
// // 从某一行一直计算到最后一行,这个时候start和end一直有值,所以不会进入到if层,这个时候n就是累计的行数(高),end-start+1就是宽
// result.push(o * (end - start + 1))
// }
// }
// }
// while (matrix.length > 1) {
// maxRect([].concat(matrix), result)
// matrix.pop()
// }
// }
// let max = 0
// result.map(item => {
// if (item > max) {
// max = item
// }
// })
// return max
// }
export var maximalRectangle = function (matrix) {
let max = 0
for (let i = 0; i < matrix.length; i++) {
for (let j = 0; j < matrix[i].length; j++) {
if (matrix[i][j] <= 0) continue
max = Math.max(max, getMax(i, j, matrix))
}
}
return max
}
function getMax (i, j, matrix) {
let max = 0; let maxW
for (let h = 0; h < matrix.length - i; h++) {
!maxW && (maxW = matrix[i + h].length - j)
if (matrix[i + h][j] <= 0) break
for (let w = 0; w < maxW; w++) {
if (matrix[i + h][j + w] <= 0) {
maxW = w
break
}
max = Math.max((w + 1) * (h + 1), max)
}
}
return max
}
// Thanks 小刚哥
+20
View File
@@ -0,0 +1,20 @@
/**
* @param A: A string
* @param B: A string
* @return: if string A contains all of the characters in B return true else return false
*/
export const compareStrings = function (A, B) {
const a = A.split('')
const b = B.split('')
for (const n in b) {
const tmp = a.indexOf(b[n])
if (tmp === -1) {
return false
} else {
a.splice(tmp, 1)
}
}
return true
}
+7
View File
@@ -0,0 +1,7 @@
/**
* @param {number[]} nums
* @return {boolean}
*/
export const containsDuplicate = function (nums) {
return new Set(nums).size !== nums.length
}
+67
View File
@@ -0,0 +1,67 @@
// LeetCode 696. 计数二进制子串 https://leetcode-cn.com/problems/count-binary-substrings/
// LintCode 1079. 连续子串计数 https://www.lintcode.com/problem/count-binary-substrings/description
// 效率低
// export default (s) => {
// let count = 0
// for (let n = 0, len = s.length; n < len; n++) {
// let last = s.charAt(n)
// let time = 0
// let lastTime = 0
// for (let i = n + 1; i < len; i++) {
// if (s.charAt(i) !== last && time === lastTime) {
// count++
// break
// } else if (s.charAt(i) !== last) {
// time++
// } else if (time === 0) {
// lastTime++
// } else {
// break
// }
// }
// }
// return count
// }
// 报RegExp too big
// export default (s) => {
// // 建立数据结构,堆栈,保存数据
// let r = []
// // 给定任意子输入都返回第一个符合条件的子串
// let match = (s) => {
// let j = s.match(/^(0+|1+)/)[0]
// let o = (j[0] ^ 1).toString().repeat(j.length)
// let reg = new RegExp(`^(${j}${o})`)
// if (reg.test(s)) {
// return RegExp.$1
// } else {
// return ''
// }
// }
// // 通过for循环控制程序运行的流程
// for (let i = 0, len = s.length - 1; i < len; i++) {
// let sub = match(s.slice(i))
// if (sub) r.push(sub)
// }
// return r.length
// }
export default (s) => {
// 来自 Somnus
// pre 前一个数字连续出现的次数,cur 当前数字连续出现的次数,result 结果子串个数
let pre = 0; let cur = 1; let result = 0
for (let i = 0, len = s.length - 1; i < len; i++) {
// 判断当前数字是否与后一个数字相同
if (s[i] === s[i + 1]) { // 相同,则当前数字出现的次数cur加1
cur++
} else { // 不同,则当前数字事实上变成了前一个数字,当前数字的次数重置为1
pre = cur
cur = 1
}
if (pre >= cur) { // 前一个数字出现的次数 >= 后一个数字出现的次数,则一定包含满足条件的子串
result++
}
}
return result
}
+58
View File
@@ -0,0 +1,58 @@
// LeetCode 10. 正则表达式匹配 https://leetcode-cn.com/problems/regular-expression-matching/
// LintCode 154. 正则表达式匹配 https://www.lintcode.com/problem/regular-expression-matching/description
// 'mississippi', 'mis*is*ip*.' 测试不通过
// export default (str, mode) => {
// const strLen = str.length
// const modeArr = mode.match(/([a-z.]\*)|([a-z]+(?=([a-z.]\*)|$))/g) // 筛选无模式和有模式
// if (!modeArr) return false
// let cur = 0
// for (let n = 0, len = modeArr.length; n < len; n++) {
// // 匹配模式结果分类
// // 分三类:.*|a*|bcde
// const s = modeArr[n].split('')
// if (s[1] === '*') { // 如果第二位是'*',则为有模式
// if (s[0] === '.') { // 第一种模式
// return true
// } else { // 第二种模式,直接移到相等的最后面
// while (str[cur] === s[0]) {
// cur++
// }
// }
// } else { // 无模式
// for (let i = 0, sLen = s.length; i < sLen; i++) {
// if (s[i] !== str[cur++]) { // 注意,cur++每一次都会被执行
// return false
// }
// }
// }
// }
// return cur === strLen
// }
export default (str, mode) => {
const isMatch = (s, p) => {
// 边界情况,如果s和p都为空,说明处理结束了,返回true,否则返回false
if (p.length <= 0) {
return !s.length
}
// 判断p模式字符串的第一个字符和s字符串的第一个字符是不是匹配
let match = false
if (s.length > 0 && (p[0] === s[0] || p[0] === '.')) {
match = true
}
// p有模式的
if (p.length > 1 && p[1] === '*') {
// 第一种情况:s*匹配0个字符
// 第二种情况:s*匹配1个字符,递归下去,用来表示s*匹配多个s
return isMatch(s, p.slice(2)) || (match && isMatch(s.slice(1), p))
} else {
return match && isMatch(s.slice(1), p.slice(1))
}
}
return isMatch(str, mode)
}
+6
View File
@@ -0,0 +1,6 @@
// LeetCode 459. 重复的子字符串 https://leetcode-cn.com/problems/repeated-substring-pattern/
// LintCode 1227. 重复的子串模式 https://www.lintcode.com/problem/repeated-substring-pattern/description
export default (str) => {
return /^(\w+)\1+$/.test(str)
}
+56
View File
@@ -0,0 +1,56 @@
// LeetCode 93. 复原IP地址 https://leetcode-cn.com/problems/restore-ip-addresses/
// LintCode 426. 恢复IP地址 https://www.lintcode.com/problem/restore-ip-addresses/description
export default (str) => {
const result = []
if (str === '0000') return ['0.0.0.0']
// 递归函数
const recur = (cur, sub) => {
if (cur.length === 4 && cur.join('') === str) {
if (!cur.every(item => Number(item) === 0)) {
result.push(cur.join('.'))
}
} else {
for (let n = 0, len = Math.min(3, sub.length); n < len; n++) {
const start = Number(sub.substr(0, n + 1))
const end = sub.substr(n + 1)
if (start < 256 && end.length <= (9 - cur.length * 3)) {
recur([...cur, start], end)
}
}
}
}
recur([], str)
return result
}
// 快乐动起来老师的解法:
// export default (str) => {
// // 保存所有符合条件的IP地址
// let r = []
// // 分四步递归处理ip分段
// let search = (cur, sub) => {
// // 非法输入过滤,LeetCode测试用例(111111111111111111111111111111111111111111111111111111111111)
// if (sub.length > 12) {
// return
// }
// // 边界条件
// if (cur.length === 4 && cur.join('') === str) {
// r.push(cur.join('.'))
// } else {
// // 正常的处理过程
// for (let i = 0, len = Math.min(3, sub.length), tmp; i < len; i++) {
// tmp = sub.substr(0, i + 1)
// if (tmp - 256 < 0) {
// // 转换下数据类型,如 01为1(LeetCode测试用例)
// search(cur.concat([tmp * 1]), sub.substr(i + 1))
// }
// }
// }
// }
// search([], str)
// return r
// }
+12
View File
@@ -0,0 +1,12 @@
// 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
export default (s) => {
return s.split(' ').map(item => {
let tmp = ''
for (let n = item.length; n >= 0; n--) {
tmp += item.charAt(n)
}
return tmp
}).join(' ')
}
+3
View File
@@ -0,0 +1,3 @@
export const isUnique = (str) => {
return new Set(str.split('')).size === str.length
}
+28
View File
@@ -0,0 +1,28 @@
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {number[]}
*/
export const rightSideView = function (root) {
if (!root) return []
const queue = [root] // 队列 把树顶加入队列
const arr = [] // 用来存储每层最后个元素值
while (queue.length > 0) {
let len = queue.length
while (len) {
const node = queue.shift() // 取出队列第一个元素
if (len === 1) arr.push(node.val) // 当是 当前一层的最后一个元素时,把值加入arr
if (node.left) queue.push(node.left) // 继续往队列添加元素
if (node.right) queue.push(node.right)
len--
}
}
return arr
}
+51
View File
@@ -0,0 +1,51 @@
import { updateMatrix } from '../../src/array/01-matrix'
test('01 矩阵', () => {
expect(updateMatrix([
[0, 0, 0],
[0, 1, 0],
[0, 0, 0]
])).toEqual([
[0, 0, 0],
[0, 1, 0],
[0, 0, 0]
])
expect(updateMatrix([
[0, 0, 0],
[0, 1, 0],
[1, 1, 1]
])).toEqual([
[0, 0, 0],
[0, 1, 0],
[1, 2, 1]
])
expect(updateMatrix([
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
])).toEqual([
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
])
expect(updateMatrix([
[0, 1, 0, 1, 1],
[1, 1, 0, 0, 1],
[0, 0, 0, 1, 0],
[1, 0, 1, 1, 1],
[1, 0, 0, 0, 1]
])).toEqual([
[0, 1, 0, 1, 2],
[1, 1, 0, 0, 1],
[0, 0, 0, 1, 0],
[1, 0, 1, 1, 1],
[1, 0, 0, 0, 1]
])
})
@@ -0,0 +1,9 @@
import maxProfit from '../../src/array/best-time-to-buy-and-sell-stock-ii'
test('maxProfit', () => {
expect(maxProfit([7, 1, 5, 3, 6, 4])).toEqual(7)
expect(maxProfit([1, 2, 3, 4, 5])).toEqual(4)
expect(maxProfit([7, 6, 4, 3, 1])).toEqual(0)
expect(maxProfit([])).toEqual(0)
expect(maxProfit([2, 1, 2, 0, 1])).toEqual(2)
})
+9
View File
@@ -0,0 +1,9 @@
import { search } from '../../src/array/binary-search'
test('BinarySearch', () => {
expect(search([-1, 0, 3, 5, 9, 12], 9)).toEqual(4)
expect(search([-1, 0, 3, 5, 9, 12], 2)).toEqual(-1)
expect(search([1, 4, 4, 5, 7, 7, 8, 9, 9, 10], 1)).toEqual(0)
expect(search([1, 2, 3, 3, 4, 5, 10], 3)).toEqual(2)
expect(search([1, 2, 3, 3, 4, 5, 10], 6)).toEqual(-1)
})
+11
View File
@@ -0,0 +1,11 @@
import bubbleSort from '../../src/array/bubble-sort'
test('bubbleSort', () => {
expect(bubbleSort([1, 2, 3])).toEqual([1, 2, 3])
expect(bubbleSort([3, 2, 1])).toEqual([1, 2, 3])
expect(bubbleSort([])).toEqual([])
expect(bubbleSort([3, 6, 4, 5, 6, 8])).toEqual([3, 4, 5, 6, 6, 8])
expect(bubbleSort([1, 1, 1])).toEqual([1, 1, 1])
expect(bubbleSort([-1, -10, 3])).toEqual([-10, -1, 3])
expect(bubbleSort([7, 2, 8, 3, 6, 3])).toEqual([2, 3, 3, 6, 7, 8])
})
+7
View File
@@ -0,0 +1,7 @@
import canPlaceFlowers from '../../src/array/can-place-flowers'
test('canPlaceFlowers', () => {
expect(canPlaceFlowers([1, 0, 0, 0, 1], 1)).toEqual(true)
expect(canPlaceFlowers([1, 0, 0, 0, 1], 2)).toEqual(false)
expect(canPlaceFlowers([1, 0, 0, 0, 1, 0, 0], 2)).toEqual(true)
})
+7
View File
@@ -0,0 +1,7 @@
import circularArrayLoop from '../../src/array/circular-array-loop'
test('circularArrayLoop', () => {
expect(circularArrayLoop([2, -1, 1, 2, 2])).toEqual(true)
expect(circularArrayLoop([-1, 2])).toEqual(false)
expect(circularArrayLoop([-2, 1, -1, -2, -2])).toEqual(false)
})
@@ -0,0 +1,7 @@
import { maxArea } from '../../src/array/container-with-most-water'
test('盛最多水的容器', () => {
expect(maxArea([1, 8, 6, 2, 5, 4, 8, 3, 7])).toBe(49)
expect(maxArea([1, 3, 2])).toBe(2)
expect(maxArea([1, 3, 2, 2])).toBe(4)
})
@@ -0,0 +1,7 @@
import { numberOfSubarrays } from '../../src/array/count-number-of-nice-subarrays'
test('统计「优美子数组」', () => {
expect(numberOfSubarrays([1, 1, 2, 1, 1], 3)).toBe(2)
expect(numberOfSubarrays([2, 4, 6], 1)).toBe(0)
expect(numberOfSubarrays([2, 2, 2, 1, 2, 2, 1, 2, 2, 2], 2)).toBe(16)
})
+24
View File
@@ -0,0 +1,24 @@
import { includesInStr, getStrCopyByNum, getMaxRepetitions } from '../../src/array/count-the-repetitions'
test('判断从 s2 中删除某些字符是否可以变为 s1', () => {
expect(includesInStr('abc', 'ab')).toBe(1)
expect(includesInStr('acb', 'ab')).toBe(1)
expect(includesInStr('ab', 'ab')).toBe(1)
expect(includesInStr('ac', 'ab')).toBe(0)
expect(includesInStr('aa', 'a')).toBe(2)
expect(includesInStr('aaa', 'a')).toBe(3)
expect(includesInStr('abcabc', 'abb')).toBe(1)
})
test('获取重复字符串', () => {
expect(getStrCopyByNum('abc', 2)).toBe('abcabc')
expect(getStrCopyByNum('abc', 3)).toBe('abcabcabc')
})
test('统计重复个数', () => {
expect(getMaxRepetitions('abc', 4, 'ab', 2)).toBe(2)
expect(getMaxRepetitions('acb', 4, 'ab', 2)).toBe(2)
expect(getMaxRepetitions('abc', 4, 'abb', 2)).toBe(1)
expect(getMaxRepetitions('aaa', 3, 'aa', 1)).toBe(4)
expect(getMaxRepetitions('abccab', 4, 'abc', 2)).toBe(2)
})
@@ -0,0 +1,9 @@
import { commonChars } from '../../src/array/find-common-characters'
describe('查找常用字符', () => {
test('查找常用字符', () => {
expect(commonChars(['bella', 'label', 'roller']).sort()).toEqual(['e', 'l', 'l'].sort())
expect(commonChars(['cool', 'lock', 'cook']).sort()).toEqual(['c', 'o'].sort())
expect(commonChars(['acabcddd', 'bcbdbcbd', 'baddbadb', 'cbdddcac', 'aacbcccd', 'ccccddda', 'cababaab', 'addcaccd']).sort()).toEqual([].sort())
})
})
+11
View File
@@ -0,0 +1,11 @@
import firstMissingPositive from '../../src/array/first-missing-positive'
test('缺失的第一个正数', () => {
expect(firstMissingPositive([-1])).toBe(1)
expect(firstMissingPositive([0])).toBe(1)
expect(firstMissingPositive([])).toBe(1)
expect(firstMissingPositive([3, 2, -1])).toBe(1)
expect(firstMissingPositive([3, 4, -1, 1])).toBe(2)
expect(firstMissingPositive([1, 2, 0])).toBe(3)
expect(firstMissingPositive([7, 8, 9, 11, 12])).toBe(1)
})
@@ -0,0 +1,15 @@
import firstMissingPrime, { isPrinme } from '../../src/array/first-missing-prime-number'
test('是否是素数', () => {
expect(isPrinme(0)).toBe(false)
expect(isPrinme(1)).toBe(false)
expect(isPrinme(3)).toBe(true)
expect(isPrinme(5)).toBe(true)
expect(isPrinme(7)).toBe(true)
expect(isPrinme(6)).toBe(false)
})
test('缺失的第一个素数', () => {
expect(firstMissingPrime([3, 5, 7])).toBe(2)
expect(firstMissingPrime([2, 3, 5, 7, 11, 13, 17, 23, 29])).toBe(19)
})
+7
View File
@@ -0,0 +1,7 @@
import grayCode from '../../src/array/gray-code'
test('grayCode', () => {
expect(grayCode(1)).toEqual([0, 1])
expect(grayCode(2)).toEqual([0, 1, 3, 2])
expect(grayCode(0)).toEqual([0])
})
+6
View File
@@ -0,0 +1,6 @@
import { canJump } from '../../src/array/jump-game'
test('跳跃游戏', () => {
expect(canJump([2, 3, 1, 1, 4])).toBe(true)
expect(canJump([3, 2, 1, 0, 4])).toBe(false)
})
@@ -0,0 +1,6 @@
import findKthLargest from '../../src/array/kth-largest-element-in-an-array'
test('findKthLargest', () => {
expect(findKthLargest([3, 2, 1, 5, 6, 4], 2)).toEqual(5)
expect(findKthLargest([3, 2, 3, 1, 2, 4, 5, 5, 6], 4)).toEqual(4)
})
@@ -0,0 +1,5 @@
import letterCombinations from '../../src/array/letter-combinations-of-a-phone-number'
test('letterCombinations', () => {
expect(letterCombinations('23')).toEqual(['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf'])
})
+20
View File
@@ -0,0 +1,20 @@
import loopAscArray from '../../src/array/loop-asc-array'
test('loopAscArray', () => {
expect(loopAscArray([0, 3, 4, 6, 7], 0)).toEqual(true)
expect(loopAscArray([6, 7, 0, 3, 4], 0)).toEqual(true)
expect(loopAscArray([6, 7, 0, 3, 4], 5)).toEqual(false)
expect(loopAscArray([1, 2, 3, 4, 5], 6)).toEqual(false)
expect(loopAscArray([1, 2, 3, 4, 5], 1)).toEqual(true)
expect(loopAscArray([3, 4, 5, 1, 1, 2], 1)).toEqual(true)
expect(loopAscArray([3, 4, 5, 1, 1, 2], 6)).toEqual(false)
expect(loopAscArray([3, 4, 5, 1, 1, 2], 0)).toEqual(false)
expect(loopAscArray([1, 0, 1, 1, 1], 0)).toEqual(true)
expect(loopAscArray([1, 0, 1, 1, 1], 2)).toEqual(false)
expect(loopAscArray([3], 2)).toEqual(false)
expect(loopAscArray([2], 2)).toEqual(true)
expect(loopAscArray([1, 1, 1], 2)).toEqual(false)
expect(loopAscArray([1, 1, 1], 1)).toEqual(true)
expect(loopAscArray([1, 1, 1, 0], 1)).toEqual(true)
expect(loopAscArray([1, 1, 1, 0], 2)).toEqual(false)
})
+11
View File
@@ -0,0 +1,11 @@
import { majorityElement } from '../../src/array/majority-element'
test('主元素', () => {
expect(majorityElement([1, 2, 5, 9, 5, 9, 5, 5, 5])).toBe(5)
expect(majorityElement([1, 1, 1, 1, 2, 2, 2])).toBe(1)
expect(majorityElement([1, 1, 1, 2, 2, 2, 2])).toBe(2)
expect(majorityElement([3, 2])).toBe(-1)
expect(majorityElement([2, 2, 1, 1, 1, 2, 2])).toBe(2)
expect(majorityElement([1])).toBe(1)
expect(majorityElement([2, 2])).toBe(2)
})
+1
View File
@@ -0,0 +1 @@
export default [55555, 55554, 55553, 55552, 55551, 55550, 55549, 55548, 55547, 55546, 55545, 55544, 55543, 55542, 55541, 55540, 55539, 55538, 55537, 55536, 55535, 55534, 55533, 55532, 55531, 55530, 55529, 55528, 55527, 55526, 55525, 55524, 55523, 55522, 55521, 55520, 55519, 55518, 55517, 55516, 55515, 55514, 55513, 55512, 55511, 55510, 55509, 55508, 55507, 55506, 55505, 55504, 55503, 55502, 55501, 55500, 55499, 55498, 55497, 55496, 55495, 55494, 55493, 55492, 55491, 55490, 55489, 55488, 55487, 55486, 55485, 55484, 55483, 55482, 55481, 55480, 55479, 55478, 55477, 55476, 55475, 55474, 55473, 55472, 55471, 55470, 55469, 55468, 55467, 55466, 55465, 55464, 55463, 55462, 55461, 55460, 55459, 55458, 55457, 55456, 55455, 55454, 55453, 55452, 55451, 55450, 55449, 55448, 55447, 55446, 55445, 55444, 55443, 55442, 55441, 55440, 55439, 55438, 55437, 55436, 55435, 55434, 55433, 55432, 55431, 55430, 55429, 55428, 55427, 55426, 55425, 55424, 55423, 55422, 55421, 55420, 55419, 55418, 55417, 55416, 55415, 55414, 55413, 55412, 55411, 55410, 55409, 55408, 55407, 55406, 55405, 55404, 55403, 55402, 55401, 55400, 55399, 55398, 55397, 55396, 55395, 55394, 55393, 55392, 55391, 55390, 55389, 55388, 55387, 55386, 55385, 55384, 55383, 55382, 55381, 55380, 55379, 55378, 55377, 55376, 55375, 55374, 55373, 55372, 55371, 55370, 55369, 55368, 55367, 55366, 55365, 55364, 55363, 55362, 55361, 55360, 55359, 55358, 55357, 55356, 55355, 55354, 55353, 55352, 55351, 55350, 55349, 55348, 55347, 55346, 55345, 55344, 55343, 55342, 55341, 55340, 55339, 55338, 55337, 55336, 55335, 55334, 55333, 55332, 55331, 55330, 55329, 55328, 55327, 55326, 55325, 55324, 55323, 55322, 55321, 55320, 55319, 55318, 55317, 55316, 55315, 55314, 55313, 55312, 55311, 55310, 55309, 55308, 55307, 55306, 55305, 55304, 55303, 55302, 55301, 55300, 55299, 55298, 55297, 55296, 55295, 55294, 55293, 55292, 55291, 55290, 55289, 55288, 55287, 55286, 55285, 55284, 55283, 55282, 55281, 55280, 55279, 55278, 55277, 55276, 55275, 55274, 55273, 55272, 55271, 55270, 55269, 55268, 55267, 55266, 55265, 55264, 55263, 55262, 55261, 55260, 55259, 55258, 55257, 55256, 55255, 55254, 55253, 55252, 55251, 55250, 55249, 55248, 55247, 55246, 55245, 55244, 55243, 55242, 55241, 55240, 55239, 55238, 55237, 55236, 55235, 55234, 55233, 55232, 55231, 55230, 55229, 55228, 55227, 55226, 55225, 55224, 55223, 55222, 55221, 55220, 55219, 55218, 55217, 55216, 55215, 55214, 55213, 55212, 55211, 55210, 55209, 55208, 55207, 55206, 55205, 55204, 55203, 55202, 55201, 55200, 55199, 55198, 55197, 55196, 55195, 55194, 55193, 55192, 55191, 55190, 55189, 55188, 55187, 55186, 55185, 55184, 55183, 55182, 55181, 55180, 55179, 55178, 55177, 55176, 55175, 55174, 55173, 55172, 55171, 55170, 55169, 55168, 55167, 55166, 55165, 55164, 55163, 55162, 55161, 55160, 55159, 55158, 55157, 55156, 55155, 55154, 55153, 55152, 55151, 55150, 55149, 55148, 55147, 55146, 55145, 55144, 55143, 55142, 55141, 55140, 55139, 55138, 55137, 55136, 55135, 55134, 55133, 55132, 55131, 55130, 55129, 55128, 55127, 55126, 55125, 55124, 55123, 55122, 55121, 55120, 55119, 55118, 55117, 55116, 55115, 55114, 55113, 55112, 55111, 55110, 55109, 55108, 55107, 55106, 55105, 55104, 55103, 55102, 55101, 55100, 55099, 55098, 55097, 55096, 55095, 55094, 55093, 55092, 55091, 55090, 55089, 55088, 55087, 55086, 55085, 55084, 55083, 55082, 55081, 55080, 55079, 55078, 55077, 55076, 55075, 55074, 55073, 55072, 55071, 55070, 55069, 55068, 55067, 55066, 55065, 55064, 55063, 55062, 55061, 55060, 55059, 55058, 55057, 55056, 55055, 55054, 55053, 55052, 55051, 55050, 55049, 55048, 55047, 55046, 55045, 55044, 55043, 55042, 55041, 55040, 55039, 55038, 55037, 55036, 55035, 55034, 55033, 55032, 55031, 55030, 55029, 55028, 55027, 55026, 55025, 55024, 55023, 55022, 55021, 55020, 55019, 55018, 55017, 55016, 55015, 55014, 55013, 55012, 55011, 55010, 55009, 55008, 55007, 55006, 55005, 55004, 55003, 55002, 55001, 55000, 54999, 54998, 54997, 54996, 54995, 54994, 54993, 54992, 54991, 54990, 54989, 54988, 54987, 54986, 54985, 54984, 54983, 54982, 54981, 54980, 54979, 54978, 54977, 54976, 54975, 54974, 54973, 54972, 54971, 54970, 54969, 54968, 54967, 54966, 54965, 54964, 54963, 54962, 54961, 54960, 54959, 54958, 54957, 54956, 54955, 54954, 54953, 54952, 54951, 54950, 54949, 54948, 54947, 54946, 54945, 54944, 54943, 54942, 54941, 54940, 54939, 54938, 54937, 54936, 54935, 54934, 54933, 54932, 54931, 54930, 54929, 54928, 54927, 54926, 54925, 54924, 54923, 54922, 54921, 54920, 54919, 54918, 54917, 54916, 54915, 54914, 54913, 54912, 54911, 54910, 54909, 54908, 54907, 54906, 54905, 54904, 54903, 54902, 54901, 54900, 54899, 54898, 54897, 54896, 54895, 54894, 54893, 54892, 54891, 54890, 54889, 54888, 54887, 54886, 54885, 54884, 54883, 54882, 54881, 54880, 54879, 54878, 54877, 54876, 54875, 54874, 54873, 54872, 54871, 54870, 54869, 54868, 54867, 54866, 54865, 54864, 54863, 54862, 54861, 54860, 54859, 54858, 54857, 54856, 54855, 54854, 54853, 54852, 54851, 54850, 54849, 54848, 54847, 54846, 54845, 54844,Line truncated
+10
View File
@@ -0,0 +1,10 @@
import maximumGap from '../../src/array/maximum-gap'
import inData from './maximum-gap.test.data'
test('最大间距', () => {
expect(maximumGap([3, 6, 9, 1])).toBe(3)
expect(maximumGap([10])).toBe(0)
expect(maximumGap([13, 16, 19, 1])).toBe(12)
expect(maximumGap([1, 3, 100])).toBe(97)
expect(maximumGap(inData)).toBe(2147428092)
})
+37
View File
@@ -0,0 +1,37 @@
import { merge, mergeLintCode } from '../../src/array/merge-intervals'
test('合并区间 - LeetCode', () => {
expect(merge([[1, 3], [2, 6], [8, 10], [15, 18]])).toEqual([[1, 6], [8, 10], [15, 18]])
expect(merge([[1, 4], [4, 5]])).toEqual([[1, 5]])
expect(merge([[1, 3]])).toEqual([[1, 3]])
expect(merge([[1, 4], [5, 6]])).toEqual([[1, 4], [5, 6]])
expect(merge([[1, 4], [1, 4]])).toEqual([[1, 4]])
expect(merge([[1, 4], [2, 3]])).toEqual([[1, 4]])
expect(merge([[1, 4], [0, 2], [3, 5]])).toEqual([[0, 5]])
expect(merge([[1, 3], [4, 6], [4, 7]])).toEqual([[1, 3], [4, 7]])
expect(merge([[2, 3], [2, 2], [3, 3], [1, 3], [5, 7], [2, 2], [4, 6]])).toEqual([[1, 3], [4, 7]])
})
test('合并区间 - LintCode', () => {
let input = `(74, 78), (61, 63), (46, 50), (51, 54), (50, 50), (60, 64), (39, 42), (25, 27), (91, 95), (14, 16), (85, 85), (5, 7), (45, 46), (45, 49), (66, 66), (73, 73), (25, 26), (25, 26), (45, 48), (67, 67), (63, 65), (82, 84), (90, 92), (47, 49), (3, 4), (1, 5), (64, 66), (73, 77), (90, 94), (20, 21), (84, 87), (48, 49), (80, 80), (85, 85), (53, 55), (21, 23), (31, 34), (71, 75), (62, 65), (8, 9), (32, 33), (7, 8), (20, 22), (57, 57), (51, 53), (18, 21), (71, 75), (49, 50), (44, 45), (28, 31), (38, 42), (15, 17), (4, 7), (48, 52), (9, 10), (37, 38), (69, 70), (89, 89), (28, 29), (52, 52), (75, 76), (20, 21), (90, 94), (49, 53), (56, 59), (84, 85), (79, 83), (20, 21), (90, 93), (55, 59), (76, 80), (40, 41), (40, 41), (36, 39), (79, 82), (0, 4), (11, 11), (1, 4), (42, 44), (40, 40), (32, 36), (48, 50), (76, 77), (0, 1), (89, 91), (65, 68), (51, 53), (64, 67), (90, 92), (11, 15), (92, 96), (23, 24), (36, 37), (9, 9), (79, 80), (80, 83), (26, 27), (75, 79), (2, 4), (20, 23), (34, 36), (61, 63), (46, 48), (80, 81), (29, 33), (57, 59), (60, 60), (78, 79), (57, 61), (79, 82), (41, 42), (51, 55), (92, 96), (73, 74), (6, 6), (90, 93), (34, 35), (30, 30), (81, 84), (68, 68), (7, 7), (84, 86), (57, 61), (15, 16), (54, 58), (54, 56), (6, 9), (66, 66), (37, 41), (97, 97), (36, 40), (88, 88), (42, 43), (2, 5), (34, 36), (34, 37), (99, 102), (12, 13), (33, 37), (23, 27), (74, 76), (86, 88), (87, 91), (34, 38), (95, 96), (72, 73), (70, 70), (53, 56), (83, 83), (36, 40), (77, 79), (62, 65), (93, 94), (84, 87), (6, 8), (69, 71), (37, 37), (16, 20), (11, 11), (1, 2), (34, 37), (89, 93), (85, 87), (69, 70), (97, 100), (90, 91), (80, 80), (54, 54), (31, 31), (3, 7), (50, 52), (21, 23), (79, 83), (63, 63), (40, 41), (48, 52), (41, 43), (30, 32), (31, 33), (48, 51), (10, 10), (6, 8), (95, 97), (20, 22), (3, 6), (68, 71), (48, 50), (92, 94), (31, 31), (70, 73), (24, 24), (49, 49), (60, 60), (44, 45), (84, 88), (72, 76), (35, 38), (88, 88), (91, 94), (9, 13), (84, 87), (99, 101), (20, 21), (11, 14), (98, 101), (27, 29), (4, 5), (40, 44), (8, 9), (7, 9), (81, 85), (38, 39), (58, 62), (98, 99), (39, 39), (47, 50), (90, 91), (7, 7), (37, 41), (65, 67), (52, 54), (62, 65), (21, 23), (24, 28), (38, 40), (74, 75), (63, 67), (87, 88), (43, 46), (74, 77), (98, 99), (6, 9), (67, 68), (50, 51), (85, 85), (96, 100), (60, 63), (50, 51), (12, 13), (62, 62), (58, 59), (22, 24), (1, 2), (95, 96), (51, 51), (79, 83), (43, 46), (89, 90), (4, 5), (19, 20), (59, 59), (82, 86), (73, 75), (52, 54), (59, 63), (88, 92), (3, 5), (43, 44), (75, 76), (52, 54), (13, 17), (28, 29), (74, 74), (19, 19), (61, 65), (71, 71), (6, 6), (91, 93), (90, 93), (69, 70), (10, 14), (70, 70), (23, 24), (21, 25), (9, 9), (78, 80), (9, 12), (30, 30), (28, 28), (65, 67), (41, 44), (14, 18), (94, 95), (83, 87), (1, 4), (85, 86), (14, 16), (28, 31), (25, 29), (89, 93), (75, 77), (8, 9), (77, 78), (24, 25), (93, 97), (48, 49), (78, 82), (85, 89), (20, 24), (8, 12), (74, 77), (37, 40), (52, 53), (26, 29), (67, 69), (64, 66), (34, 34), (31, 33), (68, 68), (70, 71), (96, 96), (47, 48), (84, 86), (50, 52), (53, 56), (83, 85), (3, 3), (16, 19), (38, 42), (86, 87), (62, 64), (0, 3), (79, 82), (12, 14), (90, 92), (60, 62), (4, 6), (13, 17), (92, 96), (98, 100), (74, 75), (25, 25), (53, 56), (38, 40), (39, 40), (98, 101), (30, 33), (2, 2), (34, 35), (9, 13), (49, 49), (11, 11), (29, 31), (94, 97), (93, 97), (71, 73), (77, 80), (49, 50), (41, 43), (23, 25), (15, 18), (86, 87), (23, 23), (8, 10), (6, 10), (82, 84), (39, 39), (13, 14), (22, 26), (94, 94), (4, 6), (35, 36), (65, 66), (64, 67), (24, 28), (91, 92), (12, 16), (37, 40), (69, 71), (97, 99), (67, 68), (35, 38), (77, 80), (79, 80), (7, 8), (19, 22), (43, 44), (97, 98), (42, 43), (71, 72), (1, 5), (58, 58), (43, 45), (5, 9), (45, 48), (92, 96), (34, 36), (22, 25), (27, 29), (15, 16), (80, 81), (2, 2), (92, 96), (36, 40), (12, 12), (1, 4), (74, 75), (31, 34), (10, 13), (34, 36), (91, 92), (71, 74), (5, 9), (93, 97), (48, 48), (71, 71), (46, 49), (55, 58), (72, 76), (73, 74), (4, 5), (2, 2), (89, 92), (48, 52), (21, 24), (59, 59), (61, 61), (95, 99), (76, 79), (3, 4), (49, 53), (8, 8), (99, 100), (34, 37), (60, 64), (60, 61), (85, 87), (46, 50), (47, 49), (25, 25), (82, 86), (85, 85), (67, 69), (14, 14), (73, 76), (72, 76), (44, 46), (21, 25), (48, 50), (67, 67), (66, 68), (28, 29), (41, 43), (77, 80), (74, 77), (9, 12), (87, 88), (3, 7), (79, 82), (50, 54), (88, 92), (78, 80), (58, 62), (28, 30), (7, 10), (19, 19), (27, 30), (77, 81), (75, 79), (57, 58), (9, 10), (9, 11), (13, 17), (3, 7), (34, 34), (48, 50), (31, 34), (7, 7), (77, 77), (49, 50), (83, 86), (62, 63), (16, 20), (80, 83), (45, 49), (44, 44), (8, 8), (4, 5), (70, 72), (17, 21), (65, 67), (27, 28), (95, 96), (38, 40), (21, 23), (61, 63), (8, 11), (68, 69), (14, 14), (20, 21), (41, 42), (66, 70), (22, 24), (22, 24), (30, 34), (48, 50), (8, 10), (43, 46), (13, 15), (28, 30), (21, 25), (44, 48), (12, 16), (6, 7), (16, 19), (37, 39), (94, 95), (7, 8), (78, 82), (60, 60 Line truncated
(65, 68), (22, 25), (90, 90), (75, 75), (53, 55), (61, 62), (88, 92), (29, 33), (11, 13), (22, 23), (50, 53), (36, 36), (81, 83), (64, 66), (54, 56), (86, 86), (60, 63), (8, 10), (31, 31), (53, 54), (50, 51), (2, 5), (97, 100), (27, 30), (70, 71), (9, 12), (15, 18), (98, 99), (55, 59), (66, 66), (33, 35), (82, 83), (13, 13), (48, 52), (26, 29), (32, 35), (71, 72), (66, 69), (69, 70), (28, 30), (47, 47), (65, 67), (88, 88), (11, 14), (82, 84), (5, 7), (81, 83), (13, 17), (30, 34), (38, 41), (19, 21), (36, 37), (8, 10), (11, 11), (48, 50), (74, 75), (82, 83), (10, 12), (58, 59), (17, 17), (50, 53), (60, 62), (10, 10), (26, 28), (39, 41), (0, 1), (91, 92), (54, 54), (91, 91), (30, 34), (9, 10), (87, 90), (47, 50), (65, 65), (71, 74), (98, 102), (58, 61), (58, 58), (83, 87), (13, 13), (53, 53), (86, 86), (2, 4), (97, 100), (9, 13), (84, 88), (35, 39), (62, 64), (74, 77), (39, 39), (63, 65), (71, 74), (47, 51), (93, 96), (66, 69), (58, 62), (24, 25), (16, 19), (88, 91), (23, 27), (44, 48), (68, 72), (83, 84), (13, 15), (11, 14), (3, 4), (42, 43), (51, 51), (56, 60), (73, 75), (55, 58), (93, 97), (31, 33), (9, 10), (27, 29), (20, 22), (91, 92), (51, 51), (72, 74), (84, 84), (70, 72), (13, 15), (66, 70), (2, 4), (60, 62), (96, 96), (62, 63), (46, 49), (55, 57), (16, 16), (39, 41), (7, 10), (78, 78), (10, 12), (27, 31), (89, 93), (34, 36), (62, 62), (18, 19), (74, 77), (96, 98), (46, 49), (15, 19), (4, 7), (52, 52), (58, 61), (9, 9), (26, 28), (27, 30), (41, 43), (83, 85), (56, 58), (84, 87), (69, 73), (87, 87), (85, 88), (69, 70), (41, 45), (27, 29), (7, 11), (18, 20), (23, 25), (34, 35), (67, 69), (90, 90), (21, 24), (43, 45), (42, 46), (48, 51), (34, 34), (58, 62), (70, 72), (2, 5), (63, 67), (61, 64), (9, 13), (40, 44), (58, 58), (85, 85), (89, 89), (38, 38), (0, 1), (87, 89), (60, 60), (57, 58), (22, 22), (65, 67), (42, 46), (8, 11), (49, 53), (81, 81), (0, 1), (46, 49), (96, 97), (36, 36), (59, 63), (95, 96), (55, 55), (6, 8), (22, 25), (14, 16), (79, 80), (41, 44), (51, 55), (31, 33), (18, 20), (14, 17), (34, 34), (29, 31), (43, 43), (20, 24), (91, 93), (66, 69), (2, 4), (65, 67), (35, 36), (74, 75), (63, 63), (40, 41), (65, 68), (18, 18), (36, 40), (6, 8), (96, 96), (56, 60), (52, 53), (46, 49), (44, 46), (41, 44), (36, 39), (75, 78), (42, 46), (90, 90), (17, 19), (23, 27), (5, 8), (69, 72), (77, 77), (67, 70), (62, 66), (64, 68), (0, 0), (9, 10), (74, 76), (95, 95), (13, 15), (34, 34), (72, 73), (12, 13), (58, 58), (75, 75), (28, 32), (61, 61), (72, 75), (30, 31), (52, 56), (1, 1), (5, 7), (53, 57), (65, 68), (42, 45), (71, 74), (33, 33), (4, 4), (36, 40), (80, 83), (81, 81), (7, 9), (17, 18), (23, 25), (18, 20), (41, 42), (32, 35), (85, 88), (30, 30), (86, 88), (80, 84), (52, 55), (56, 57), (10, 14), (22, 24), (7, 10), (2, 4), (98, 102), (50, 51), (18, 21), (0, 2), (91, 91), (10, 12), (23, 23), (79, 80), (64, 64), (71, 72), (25, 29), (24, 25), (24, 25), (30, 33), (2, 2), (50, 52), (56, 57), (25, 25), (21, 21), (87, 87), (10, 14), (42, 45), (90, 91), (95, 96), (33, 36), (23, 27), (97, 99), (47, 50), (46, 48), (57, 57), (14, 18), (52, 53), (12, 14), (98, 102), (2, 2), (99, 99), (34, 37), (98, 99), (66, 66), (83, 83), (63, 66), (11, 14), (57, 60), (38, 41), (87, 89), (3, 5), (7, 9), (25, 29), (36, 39), (5, 6), (60, 61), (56, 60), (1, 5), (23, 26), (52, 53), (20, 20), (64, 67), (80, 81), (93, 97), (77, 79), (66, 68), (86, 89), (40, 41), (45, 48), (34, 36), (19, 23), (59, 59), (41, 41), (82, 86), (80, 84), (22, 24), (1, 4), (35, 37), (59, 62), (1, 4), (61, 63), (21, 23), (93, 96), (11, 11), (41, 43), (92, 95), (44, 45), (40, 40), (64, 66), (1, 5), (8, 11), (97, 97), (61, 65), (44, 46), (65, 67), (13, 14), (16, 17), (25, 29), (99, 102), (51, 53), (86, 90), (57, 57), (47, 50), (67, 68), (20, 23), (8, 9), (43, 45), (43, 44), (41, 43), (28, 29), (36, 39), (84, 86), (79, 81), (14, 14), (50, 50), (23, 24), (9, 9), (18, 20), (78, 78), (20, 21), (5, 8), (32, 35), (37, 39), (4, 8), (66, 66), (37, 39), (78, 80), (54, 54), (36, 39), (40, 41), (34, 37), (75, 75), (96, 96), (4, 5), (31, 31), (77, 80), (5, 6), (37, 40), (40, 43), (74, 75), (30, 31), (8, 12), (85, 88), (71, 72), (83, 84), (8, 10), (75, 75), (65, 68), (80, 84), (49, 52), (94, 98), (52, 54), (92, 96), (95, 95), (34, 38), (91, 91), (32, 32), (26, 29), (15, 17), (39, 42), (8, 12), (68, 68), (34, 37), (10, 10), (2, 2), (78, 82), (91, 91), (53, 53), (71, 74), (20, 23), (69, 73), (23, 24), (64, 65), (71, 72), (98, 99), (29, 32), (10, 14), (46, 46), (82, 83), (12, 14), (68, 68), (38, 42), (73, 74), (47, 48), (91, 95), (54, 54), (83, 87), (13, 17), (30, 30), (30, 33), (48, 50), (39, 39), (61, 61), (7, 8), (41, 45), (85, 85), (62, 65), (21, 23), (66, 66), (83, 85), (40, 43), (69, 69), (67, 71), (75, 75), (19, 19), (30, 34), (17, 21), (30, 31), (6, 8), (27, 30), (9, 11), (10, 11), (87, 90), (10, 13), (56, 59), (62, 65), (83, 84), (23, 26), (65, 68), (53, 55), (4, 7), (56, 59), (5, 8), (4, 5), (76, 79), (11, 13), (95, 98), (8, 12), (9, 12), (39, 39), (63, 64), (13,Line truncated
(53, 53), (65, 68), (36, 37), (10, 14), (68, 71), (71, 71), (89, 90), (7, 9), (11, 11), (67, 67), (19, 21), (44, 46), (32, 34), (12, 16), (13, 13), (21, 22), (77, 80), (89, 89), (15, 17), (17, 17), (65, 65), (60, 61), (27, 27), (4, 7), (30, 33), (50, 52), (95, 99), (4, 4), (37, 38), (69, 69), (93, 95), (69, 72), (81, 81), (88, 89), (62, 62), (31, 31), (46, 50), (86, 86), (64, 66), (15, 16), (65, 65), (48, 51), (59, 63), (93, 96), (73, 77), (51, 52), (57, 57), (41, 44), (30, 30), (86, 86), (87, 91), (25, 25), (13, 16), (62, 66), (58, 60), (28, 31), (94, 95), (88, 89), (81, 82), (54, 58), (48, 50), (72, 72), (29, 33), (95, 95), (96, 99), (57, 60), (2, 6), (21, 24), (97, 100), (49, 49), (61, 63), (31, 33), (54, 58), (13, 15), (53, 53), (93, 94), (77, 77), (58, 60), (79, 79), (19, 21), (38, 41), (11, 13), (62, 64), (12, 13), (67, 69), (67, 70), (91, 91), (88, 88), (21, 22), (84, 88), (73, 75), (27, 28), (95, 97), (10, 11), (42, 43), (54, 56), (9, 9), (77, 80), (49, 53), (34, 35), (3, 4), (97, 97), (3, 3), (92, 92), (38, 40), (51, 53), (6, 10), (15, 16), (68, 70), (28, 29), (10, 12), (95, 99), (99, 101), (94, 94), (14, 17), (68, 70), (82, 84), (64, 64), (54, 56), (62, 62), (34, 38), (57, 59), (45, 49), (94, 97), (53, 57), (76, 79), (8, 10), (34, 38), (96, 99), (59, 61), (56, 60), (32, 35), (97, 98), (76, 77), (53, 56), (96, 100), (52, 52), (32, 36), (81, 84), (63, 67), (52, 56), (49, 49), (63, 66), (71, 73), (11, 11), (74, 77), (61, 62), (58, 61), (55, 59), (62, 65), (73, 73), (0, 2), (68, 70), (27, 28), (62, 64), (88, 92), (81, 83), (26, 28), (21, 23), (9, 11), (79, 79), (52, 52), (94, 95), (51, 55), (97, 100), (57, 59), (75, 79), (0, 3), (41, 45), (45, 48), (21, 24), (69, 73), (22, 24), (51, 54), (96, 98), (28, 28), (48, 48), (68, 70), (43, 47), (91, 92), (84, 84), (63, 64), (10, 10), (55, 58), (46, 48), (59, 63), (37, 37), (74, 75), (28, 30), (55, 56), (42, 42), (4, 4), (15, 17), (84, 85), (43, 45), (4, 8), (27, 29), (90, 94), (35, 37), (45, 46), (1, 5), (1, 4), (84, 86), (50, 54), (56, 58), (93, 96), (92, 94), (88, 92), (21, 25), (70, 74), (51, 55), (43, 44), (94, 94), (20, 21), (83, 83), (14, 18), (21, 21), (75, 78), (94, 96), (74, 75), (34, 36), (49, 52), (64, 64), (37, 37), (14, 14), (1, 4), (86, 87), (49, 49), (82, 83), (61, 61), (39, 40), (1, 1), (43, 44), (70, 70), (53, 53), (41, 45), (12, 14), (17, 21), (32, 34), (66, 70), (67, 70), (17, 20), (16, 19), (86, 89), (39, 43), (15, 18), (27, 29), (91, 92), (45, 48), (13, 14), (58, 62), (90, 93), (48, 48), (4, 7), (67, 67), (32, 33), (90, 91), (91, 93), (19, 21), (57, 57), (29, 32), (89, 90), (42, 44), (79, 81), (45, 47), (38, 39), (98, 99), (79, 81), (41, 41), (32, 35), (5, 6), (46, 49), (17, 19), (55, 58), (67, 69), (98, 99), (37, 41), (52, 56), (71, 73), (19, 23), (24, 26), (25, 25), (38, 39), (22, 26), (91, 95), (39, 42), (22, 24), (96, 100), (27, 30), (79, 83), (16, 18), (90, 90), (17, 21), (85, 85), (78, 82), (61, 64), (13, 14), (30, 34), (94, 98), (35, 35), (10, 12), (86, 88), (64, 66), (71, 72), (38, 38), (85, 86), (79, 81), (11, 14), (74, 77), (41, 43), (4, 6), (7, 10), (89, 91), (22, 22), (41, 43), (73, 74), (84, 88), (83, 84), (93, 94), (92, 93), (56, 56), (89, 92), (9, 10), (36, 39), (49, 51), (36, 40), (80, 83), (24, 25), (81, 82), (56, 60), (55, 56), (26, 28), (40, 44), (93, 94), (16, 18), (69, 73), (19, 23), (12, 16), (60, 61), (64, 65), (78, 78), (15, 15), (96, 97), (83, 85), (37, 39), (3, 3), (73, 77), (89, 90), (39, 43), (52, 54), (71, 72), (83, 86), (80, 83), (24, 26), (49, 52), (54, 58), (41, 42), (42, 44), (13, 13), (66, 68), (17, 21), (99, 100), (51, 54), (57, 59), (22, 23), (49, 50), (82, 86), (41, 41), (32, 32), (7, 8), (5, 6), (13, 14), (35, 35), (35, 38), (80, 83), (2, 2), (75, 77), (93, 94), (42, 42), (68, 68), (11, 15), (63, 63), (53, 57), (60, 61), (69, 69), (19, 20), (81, 85), (25, 28), (39, 39), (68, 70), (66, 67), (22, 23), (25, 25), (19, 21), (17, 19), (84, 84), (8, 10), (77, 78), (51, 54), (99, 101), (10, 11), (99, 102), (55, 59), (12, 14), (36, 36), (71, 73), (3, 6), (95, 98), (60, 64), (96, 100), (53, 55), (61, 62), (80, 83), (75, 76), (28, 32), (4, 7), (97, 97), (82, 82), (79, 83), (4, 6), (26, 26), (70, 70), (20, 20), (58, 60), (32, 33), (61, 61), (39, 41), (47, 48), (12, 16), (2, 3), (0, 3), (31, 34), (65, 68), (55, 59), (59, 63), (12, 13), (34, 38), (16, 17), (51, 52), (38, 41), (85, 89), (21, 22), (73, 73), (47, 47), (94, 95), (78, 82), (60, 60), (44, 46), (75, 79), (74, 74), (58, 61), (73, 77), (72, 73), (50, 50), (67, 70), (59, 63), (39, 39), (80, 84), (52, 54), (2, 3), (29, 29), (40, 41), (42, 42), (18, 18), (36, 40), (5, 7), (82, 82), (43, 47), (71, 75), (30, 33), (34, 35), (95, 96), (73, 73), (90, 90), (55, 57), (71, 72), (25, 28), (29, 33), (0, 2), (89, 93), (44, 45), (36, 37), (76, 80), (81, 83), (25, 28), (38, 38), (56, 59), (86, 90), (8, 11), (6, 6), (73, 77), (51, 54), (92, 92), (17, 17), (80, 84), (34, 38), (5, 7), (50, 52), (1, 4), (29, 31), (98, 100), (39, 43), (52, 54), (35, 36), (5, 6), (28, 31), Line truncated
(8, 10), (20, 24), (84, 88), (69, 70), (23, 26), (82, 86), (75, 78), (6, 7), (83, 85), (60, 60), (55, 57), (71, 71), (19, 22), (53, 56), (81, 84), (68, 70), (11, 14), (51, 53), (79, 82), (63, 67), (66, 66), (76, 78), (10, 12), (13, 14), (80, 80), (51, 53), (97, 101), (13, 15), (48, 51), (82, 83), (24, 26), (23, 25), (90, 92), (34, 36), (0, 2), (76, 79), (94, 98), (12, 14), (87, 90), (3, 7), (3, 7), (6, 9), (81, 82), (70, 71), (42, 46), (62, 65), (6, 9), (5, 8), (17, 21), (70, 74), (88, 92), (87, 91), (3, 3), (91, 93), (30, 31), (13, 16), (53, 55), (86, 90), (95, 98), (15, 19), (64, 68), (7, 7), (19, 21), (19, 20), (51, 52), (5, 6), (92, 92), (26, 29), (97, 101), (42, 44), (16, 17), (60, 64), (80, 84), (55, 55), (7, 9), (65, 67), (51, 55), (94, 97), (37, 37), (11, 11), (59, 61), (32, 33), (14, 14), (99, 100), (79, 81), (38, 40), (50, 53), (68, 68), (49, 52), (57, 61), (45, 49), (33, 37), (99, 101), (24, 25), (45, 45), (28, 32), (52, 52), (7, 8), (22, 24), (29, 31), (1, 3), (49, 52), (18, 18), (33, 35), (93, 95), (76, 77), (17, 18), (92, 93), (41, 42), (4, 5), (51, 53), (42, 43), (45, 49), (74, 76), (8, 12), (21, 22), (71, 74), (64, 68), (93, 95), (9, 10), (40, 42), (29, 33), (99, 100), (25, 25), (37, 38), (78, 79), (13, 13), (97, 97), (21, 24), (78, 78), (27, 31), (91, 92), (74, 77), (92, 94), (5, 6), (6, 8), (91, 91), (6, 6), (57, 60), (82, 83), (16, 18), (39, 39), (84, 87), (92, 92), (12, 12), (87, 88), (22, 23), (42, 43), (39, 39), (64, 65), (88, 90), (46, 50), (57, 59), (21, 22), (88, 91), (65, 69), (15, 19), (86, 90), (93, 97), (57, 57), (1, 5), (48, 48), (27, 28), (72, 73), (78, 81), (63, 66), (10, 14), (98, 102), (13, 17), (86, 89), (75, 76), (10, 12), (55, 56), (94, 94), (27, 30), (57, 58), (47, 48), (56, 56), (97, 97), (93, 95), (68, 69), (45, 45), (17, 17), (2, 3), (67, 70), (36, 38), (91, 92), (36, 39), (95, 97), (99, 101), (85, 86), (3, 3), (62, 62), (12, 13), (92, 92), (38, 41), (14, 15), (43, 44), (31, 33), (14, 17), (85, 86), (92, 95), (97, 98), (27, 29), (63, 64), (67, 68), (34, 36), (86, 88), (34, 37), (60, 62), (3, 4), (40, 44), (87, 87), (1, 1), (33, 33), (21, 21), (18, 18), (99, 102), (46, 47), (12, 14), (4, 8), (63, 66), (2, 6), (87, 88), (99, 102), (63, 67), (51, 51), (24, 24), (91, 93), (12, 16), (44, 47), (94, 97), (99, 102), (31, 33), (71, 71), (59, 59), (75, 79), (14, 18), (23, 26), (17, 21), (53, 56), (29, 33), (88, 88), (94, 98), (82, 84), (55, 56), (92, 92), (41, 44), (95, 99), (41, 43), (20, 22), (42, 44), (27, 30), (28, 30), (62, 62), (77, 77), (30, 33), (72, 76), (15, 16), (50, 52), (25, 26), (75, 75), (8, 12), (13, 16), (93, 97), (70, 70), (7, 7), (12, 16), (73, 75), (88, 88), (38, 38), (3, 3), (75, 75), (91, 91), (93, 95), (39, 43), (0, 2), (89, 89), (36, 38), (63, 64), (9, 10), (47, 50), (51, 52), (54, 58), (4, 6), (12, 16), (60, 60), (14, 14), (90, 91), (78, 81), (0, 4), (54, 56), (36, 36), (12, 16), (50, 50), (6, 10), (13, 16), (79, 83), (64, 67), (41, 41), (75, 78), (14, 16), (20, 24), (75, 77), (87, 90), (97, 99), (22, 24), (39, 40), (47, 50), (35, 39), (30, 33), (60, 64), (46, 50), (60, 63), (72, 73), (83, 83), (6, 6), (39, 40), (31, 35), (88, 91), (67, 68), (57, 59), (90, 93), (5, 9), (51, 53), (39, 40), (86, 90), (25, 27), (91, 92), (47, 47), (39, 42), (67, 68), (33, 35), (24, 28), (21, 21), (34, 35), (51, 52), (35, 38), (39, 39), (82, 84), (84, 87), (23, 23), (25, 26), (55, 56), (39, 41), (83, 86), (37, 38), (24, 24), (10, 14), (86, 87), (14, 14), (24, 26), (11, 15), (62, 64), (51, 52), (44, 47), (70, 73), (58, 60), (21, 21), (15, 15), (20, 23), (38, 40), (1, 1), (80, 81), (16, 17), (95, 97), (39, 43), (51, 51), (31, 34), (5, 9), (9, 13), (22, 23), (69, 72), (78, 78), (98, 101), (50, 53), (44, 48), (28, 28), (56, 59), (9, 11), (26, 30), (54, 54), (75, 75), (16, 19), (18, 21), (93, 97), (22, 24), (11, 13), (0, 1), (34, 35), (87, 87), (21, 22), (26, 30), (28, 30), (9, 11), (6, 7), (93, 93), (1, 2), (17, 21), (79, 81), (42, 44), (66, 68), (92, 96), (9, 13), (23, 23), (95, 95), (80, 84), (93, 96), (70, 73), (92, 92), (63, 66), (16, 17), (10, 14), (77, 79), (39, 41), (14, 17), (81, 84), (50, 50), (62, 63), (70, 72), (7, 9), (47, 51), (86, 88), (50, 52), (66, 68), (89, 93), (93, 93), (37, 37), (26, 26), (35, 37), (24, 28), (51, 53), (34, 37), (83, 87), (65, 68), (86, 88), (70, 71), (63, 67), (78, 81), (18, 22), (8, 10), (73, 76), (64, 65), (8, 8), (78, 81), (8, 12), (45, 46), (11, 12), (64, 65), (80, 84), (99, 101), (53, 55), (5, 9), (83, 86), (82, 83), (28, 30), (8, 9), (95, 97), (64, 68), (14, 18), (99, 101), (48, 49), (85, 85), (28, 28), (6, 9), (31, 34), (27, 29), (32, 34), (6, 6), (16, 16), (68, 69), (83, 84), (49, 52), (0, 4), (34, 35), (8, 12), (41, 43), (30, 31), (69, 72), (76, 78), (19, 19), (37, 40), (97, 101), (31, 34), (36, 40), (43, 47), (47, 48), (32, 33), (57, 61), (62, 63), (51, 52), (77, 79), (80, 83), (18, 19), (18, 20), (80, 84), (7, 10), (88, 92), (39, 40), (7, 10), (22, 24), (84, 88), (81, 83), (65, 68), (1, 1), (29, 33), (3, 5), (96, 96), (67, 6Line truncated
(43, 44), (43, 46), (97, 101), (40, 40), (78, 79), (23, 27), (65, 68), (76, 77), (42, 43), (18, 21), (77, 81), (39, 40), (75, 77), (41, 42), (45, 47), (24, 24), (70, 72), (78, 80), (3, 7), (77, 78), (82, 83), (2, 5), (91, 94), (24, 24), (51, 53), (26, 30), (88, 88), (47, 51), (54, 58), (80, 84), (66, 70), (40, 41), (23, 23), (55, 56), (89, 93), (59, 63), (37, 39), (72, 76), (92, 95), (66, 70), (43, 45), (25, 26), (10, 12), (95, 99), (13, 16), (64, 65), (32, 33), (19, 22), (26, 30), (34, 37), (11, 12), (92, 95), (8, 9), (77, 77), (16, 17), (96, 100), (40, 43), (43, 43), (98, 98), (15, 16), (18, 19), (43, 46), (87, 89), (11, 11), (89, 91), (33, 33), (43, 45), (48, 49), (45, 48), (4, 6), (26, 28), (73, 74), (26, 27), (17, 21), (7, 11), (87, 89), (15, 15), (80, 84), (45, 48), (71, 72), (41, 41), (38, 42), (34, 35), (88, 88), (16, 20), (42, 44), (48, 48), (9, 13), (84, 87), (50, 53), (62, 65), (20, 24), (20, 23), (35, 37), (96, 97), (3, 7), (11, 12), (26, 29), (80, 81), (78, 81), (10, 12), (43, 43), (39, 43), (37, 40), (82, 84), (66, 67), (77, 81), (25, 25), (44, 44), (67, 67), (18, 21), (30, 30), (16, 17), (80, 81), (22, 25), (97, 101), (30, 30), (46, 50), (44, 47), (45, 48), (23, 26), (74, 74), (2, 6), (50, 51), (11, 11), (39, 43), (93, 94), (11, 15), (29, 30), (58, 59), (1, 1), (87, 88), (47, 50), (53, 56), (69, 72), (21, 23), (61, 61), (44, 45), (46, 48), (14, 16), (17, 17), (38, 40), (26, 26), (23, 23), (93, 94), (58, 58), (88, 90), (78, 80), (83, 84), (30, 32), (81, 82), (44, 44), (46, 46), (11, 15), (87, 89), (1, 2), (83, 85), (18, 22), (42, 44), (17, 19), (75, 75), (34, 35), (73, 76), (3, 6), (96, 97), (60, 63), (37, 38), (73, 74), (96, 97), (80, 81), (13, 17), (92, 95), (26, 29), (10, 10), (5, 7), (59, 61), (2, 6), (0, 2), (7, 8), (35, 35), (42, 44), (33, 34), (3, 6), (19, 21), (94, 96), (88, 88), (38, 40), (8, 12), (95, 98), (36, 38), (97, 97), (85, 85), (41, 43), (79, 82), (93, 95), (56, 58), (14, 18), (19, 19), (48, 48), (22, 26), (42, 44), (6, 6), (94, 94), (96, 98), (85, 89), (94, 97), (80, 81), (35, 36), (69, 73), (22, 26), (81, 84), (2, 5), (19, 22), (18, 22), (15, 15), (14, 14), (54, 56), (90, 90), (87, 91), (42, 42), (23, 27), (60, 60), (20, 20), (29, 30), (61, 62), (56, 56), (81, 81), (43, 43), (35, 36), (72, 72), (53, 56), (60, 64), (10, 13), (59, 59), (94, 96), (75, 77), (43, 43), (25, 28), (82, 86), (57, 57), (57, 57), (90, 93), (27, 27), (90, 92), (98, 100), (64, 65), (0, 0), (10, 13), (80, 82), (13, 17), (76, 79), (43, 47), (75, 78), (34, 38), (22, 23), (4, 8), (56, 56), (69, 69), (32, 34), (97, 98), (74, 76), (82, 84), (39, 39), (90, 94), (19, 22), (45, 45), (43, 46), (66, 66), (57, 57), (79, 80), (44, 47), (63, 65), (30, 32), (88, 91), (44, 44), (94, 95), (99, 102), (50, 50), (25, 27), (9, 13), (47, 48), (91, 93), (47, 49), (12, 16), (10, 11), (87, 91), (74, 74), (6, 8), (35, 39), (20, 21), (32, 33), (2, 3), (94, 98), (22, 24), (96, 99), (68, 68), (42, 44), (37, 41), (69, 73), (45, 46), (40, 42), (85, 87), (35, 37), (24, 26), (38, 39), (53, 53), (62, 65), (54, 57), (64, 67), (32, 33), (63, 64), (8, 10), (13, 14), (46, 50), (95, 96), (66, 69), (76, 79), (7, 10), (95, 96), (85, 86), (79, 79), (8, 9), (98, 102), (1, 4), (94, 98), (76, 79), (87, 91), (67, 67), (82, 86), (86, 89), (57, 59), (18, 21), (56, 56), (48, 51), (56, 59), (41, 43), (76, 76), (28, 32), (16, 17), (89, 90), (15, 17), (21, 25), (54, 57), (54, 55), (2, 3), (66, 68), (45, 49), (45, 48), (9, 10), (57, 59), (79, 82), (4, 4), (0, 4), (82, 84), (18, 21), (80, 83), (93, 94), (40, 42), (89, 93), (35, 39), (87, 89), (56, 56), (86, 89), (38, 39), (99, 99), (65, 66), (46, 48), (38, 41), (6, 8), (67, 71), (96, 98), (10, 11), (48, 48), (88, 88), (96, 99), (86, 87), (77, 79), (21, 25), (47, 51), (12, 14), (7, 11), (30, 30), (51, 54), (3, 6), (41, 42), (34, 38), (70, 71), (82, 86), (98, 100), (61, 63), (97, 99), (83, 83), (41, 45), (39, 42), (15, 18), (87, 89), (32, 36), (27, 31), (38, 41), (94, 95), (6, 6), (72, 73), (77, 81), (47, 49), (28, 28), (74, 74), (7, 9), (0, 0), (13, 17), (41, 45), (94, 94), (51, 53), (50, 51), (11, 11), (14, 14), (23, 25), (37, 39), (0, 4), (53, 56), (94, 95), (60, 63), (6, 9), (78, 80), (20, 21), (98, 99), (72, 75), (42, 46), (20, 24), (7, 10), (84, 87), (40, 42), (45, 47), (6, 8), (92, 96), (45, 48), (40, 43), (6, 7), (26, 27), (5, 8), (80, 84), (60, 62), (97, 101), (28, 32), (98, 98), (52, 56), (60, 62), (93, 93), (69, 73), (3, 6), (58, 58), (51, 54), (58, 58), (96, 97), (46, 48), (35, 38), (6, 8), (31, 31), (1, 5), (76, 77), (47, 50), (85, 87), (72, 72), (65, 68), (29, 29), (7, 9), (72, 72), (37, 40), (72, 72), (19, 20), (87, 88), (49, 49), (5, 5), (52, 55), (92, 95), (9, 13), (8, 9), (98, 98), (76, 79), (74, 74), (83, 86), (44, 45), (95, 98), (91, 94), (19, 19), (91, 92), (69, 69), (4, 5), (73, 74), (85, 85), (85, 86), (56, 56), (93, 94), (26, 27), (70, 72), (27, 27), (37, 40), (13, 17), (57, 61), (52, 55), (67, 67), (34, 37), (36, 36), (14, 15), (47, 51), (78, 82), (46, 50), (29, 30), (40, 42), (Line truncated
(7, 9), (33, 34), (41, 41), (38, 41), (83, 85), (34, 34), (73, 73), (74, 75), (89, 92), (4, 5), (1, 4), (45, 46), (3, 4), (13, 15), (83, 86), (15, 15), (77, 80), (73, 76), (8, 11), (86, 89), (75, 77), (93, 94), (92, 96), (77, 78), (65, 68), (49, 50), (73, 74), (63, 65), (75, 78), (94, 94), (11, 15), (52, 52), (9, 9), (58, 60), (89, 91), (13, 14), (69, 70), (17, 19), (78, 79), (95, 98), (32, 34), (61, 61), (95, 99), (34, 34), (4, 5), (80, 80), (42, 44), (55, 57), (10, 11), (21, 25), (63, 67), (67, 69), (93, 95), (46, 47), (35, 39), (66, 68), (43, 45), (25, 28), (4, 8), (61, 64), (92, 95), (76, 76), (26, 29), (87, 90), (49, 52), (39, 43), (43, 44), (97, 98), (95, 95), (59, 60), (41, 41), (50, 54), (4, 4), (75, 78), (87, 88), (17, 21), (29, 32), (66, 68), (76, 79), (95, 98), (14, 15), (42, 46), (45, 46), (97, 97), (87, 88), (71, 74), (33, 35), (65, 69), (49, 49), (98, 101), (28, 30), (68, 70), (60, 61), (17, 20), (40, 44), (18, 19), (51, 54), (15, 16), (4, 6), (88, 91), (20, 20), (24, 24), (34, 38), (94, 94), (81, 85), (24, 28), (11, 15), (66, 69), (30, 30), (64, 66), (0, 2), (28, 31), (95, 95), (99, 101), (59, 61), (95, 96), (99, 103), (88, 88), (60, 63), (21, 22), (79, 81), (50, 51), (41, 45), (14, 17), (56, 56), (46, 47), (13, 14), (59, 59), (22, 22), (12, 15), (50, 53), (65, 69), (79, 82), (87, 87), (88, 91), (33, 33), (57, 58), (11, 14), (5, 7), (21, 22), (60, 64), (70, 73), (46, 47), (85, 85), (92, 92), (5, 9), (10, 10), (43, 47), (76, 78), (81, 82), (42, 42), (88, 92), (51, 52), (97, 100), (29, 30), (21, 22), (90, 91), (66, 69), (25, 26), (60, 62), (1, 2), (63, 66), (88, 89), (53, 54), (41, 42), (33, 36), (1, 4), (83, 87), (25, 27), (64, 65), (3, 4), (47, 48), (29, 32), (34, 38), (64, 64), (23, 26), (13, 14), (81, 82), (45, 46), (18, 21), (73, 76), (21, 22), (76, 80), (83, 84), (89, 91), (7, 9), (85, 89), (90, 92), (19, 21), (73, 77), (24, 28), (54, 56), (35, 37), (38, 40), (26, 29), (70, 74), (11, 15), (77, 80), (0, 2), (41, 45), (12, 16), (34, 36), (55, 59), (16, 16), (1, 1), (11, 11), (39, 41), (14, 15), (56, 59), (59, 61), (13, 14), (81, 81), (25, 26), (65, 66), (23, 24), (15, 17), (7, 8), (85, 85), (26, 27), (42, 46), (43, 46), (5, 7), (22, 23), (9, 12), (76, 76), (61, 61), (1, 5), (15, 19), (57, 57), (5, 8), (38, 40), (20, 21), (74, 76), (61, 63), (11, 14), (31, 35), (8, 11), (37, 39), (60, 61), (60, 61), (66, 69), (78, 82), (68, 71), (98, 100), (25, 25), (10, 11), (80, 81), (62, 66), (88, 88), (58, 62), (30, 34), (54, 54), (30, 33), (24, 26), (89, 90), (78, 80), (10, 14), (26, 26), (54, 56), (7, 7), (32, 35), (96, 98), (1, 1), (18, 22), (37, 38), (41, 45), (18, 20), (61, 64), (90, 90), (90, 94), (21, 21), (38, 39), (29, 33), (13, 14), (41, 44), (16, 17), (91, 95), (38, 42), (26, 28), (33, 33), (85, 86), (34, 34), (73, 73), (55, 58), (32, 34), (94, 97), (18, 20), (37, 41), (97, 97), (35, 35), (23, 26), (16, 17), (19, 21), (10, 12), (16, 17), (12, 13), (22, 25), (57, 60), (45, 49), (11, 13), (62, 63), (83, 83), (38, 38), (31, 33), (22, 26), (30, 33), (74, 75), (64, 65), (53, 55), (43, 47), (75, 78), (23, 25), (6, 8), (45, 49), (96, 100), (81, 84), (15, 19), (90, 90), (36, 40), (93, 97), (93, 96), (57, 61), (21, 24), (65, 67), (0, 4), (48, 48), (17, 18), (25, 25), (55, 57), (79, 81), (31, 34), (62, 65), (77, 80), (4, 8), (27, 29), (25, 27), (72, 74), (91, 94), (7, 11), (72, 75), (18, 19), (35, 37), (92, 92), (62, 62), (35, 39), (52, 53), (7, 11), (17, 18), (19, 20), (50, 51), (70, 72), (70, 72), (61, 65), (87, 91), (23, 23), (77, 78), (81, 85), (80, 80), (77, 81), (25, 27), (88, 92), (30, 30), (44, 46), (32, 32), (68, 72), (62, 62), (62, 66), (32, 32), (98, 100), (44, 45), (32, 35), (14, 14), (38, 42), (42, 42), (89, 92), (79, 83), (49, 53), (25, 25), (9, 13), (61, 65), (43, 43), (20, 22), (59, 63), (33, 36), (76, 80), (31, 31), (3, 4), (25, 26), (92, 92), (8, 9), (40, 44), (11, 15), (48, 51), (35, 39), (97, 98), (39, 41), (71, 72), (50, 52), (15, 15), (40, 44), (64, 66), (4, 8), (70, 72), (12, 14), (2, 2), (96, 98), (11, 15), (31, 31), (99, 102), (21, 22), (14, 16), (88, 90), (23, 23), (20, 21), (77, 79), (87, 91), (36, 37), (13, 16), (25, 26), (21, 23), (98, 102), (69, 69), (28, 31), (22, 24), (71, 71), (75, 78), (8, 8), (27, 30), (58, 62), (26, 28), (64, 67), (81, 81), (5, 7), (59, 59), (25, 27), (10, 13), (53, 54), (85, 88), (84, 88), (60, 63), (7, 9), (98, 98), (54, 56), (50, 52), (77, 79), (0, 1), (90, 91), (93, 95), (80, 84), (30, 30), (36, 36), (29, 30), (71, 72), (74, 77), (78, 82), (68, 70), (73, 76), (52, 55), (95, 99), (40, 44), (31, 33), (65, 69), (26, 30), (21, 22), (15, 18), (12, 14), (43, 46), (93, 95), (11, 14), (27, 28), (54, 56), (78, 78), (65, 67), (8, 10), (37, 37), (37, 37), (45, 47), (94, 95), (13, 16), (29, 33), (23, 24), (33, 37), (86, 89), (86, 89), (98, 98), (39, 39), (12, 15), (85, 89), (52, 52), (93, 97), (97, 97), (62, 64), (85, 88), (65, 65), (28, 28), (79, 81), (88, 92), (71, 71), (95, 99), (73, 76), (74, 78), (50, 53), (34, 36), (19, 21), (32, 34), (28, 28), (95Line truncated
(34, 35), (78, 78), (20, 23), (77, 78), (65, 68), (54, 57), (43, 43), (24, 27), (38, 39), (47, 48), (33, 37), (40, 43), (43, 46), (48, 48), (3, 4), (46, 48), (27, 27), (70, 72), (50, 52), (34, 34), (16, 16), (28, 29), (12, 16), (54, 55), (78, 80), (57, 58), (78, 78), (44, 45), (63, 67), (28, 29), (30, 34), (56, 59), (51, 54), (57, 59), (25, 28), (17, 18), (83, 86), (53, 56), (54, 58), (99, 101), (61, 64), (43, 44), (58, 62), (64, 65), (83, 85), (40, 44), (19, 22), (24, 26), (26, 29), (24, 25), (29, 33), (45, 49), (44, 47), (12, 15), (57, 60), (83, 84), (72, 75), (14, 16), (18, 22), (4, 7), (71, 72), (67, 69), (96, 99), (65, 67), (29, 30), (25, 28), (87, 87), (22, 23), (20, 22), (82, 82), (50, 50), (53, 55), (95, 97), (57, 60), (46, 47), (67, 67), (9, 10), (64, 64), (82, 86), (79, 80), (23, 27), (21, 21), (27, 27), (94, 98), (82, 85), (29, 29), (93, 95), (59, 62), (50, 51), (54, 57), (29, 32), (18, 21), (59, 62), (43, 46), (64, 66), (56, 60), (79, 81), (2, 3), (73, 74), (57, 59), (24, 26), (92, 96), (21, 23), (9, 10), (68, 71), (72, 72), (88, 88), (88, 88), (25, 29), (93, 95), (58, 58), (81, 83), (27, 30), (95, 97), (31, 34), (12, 12), (92, 96), (76, 79), (8, 9), (37, 41), (1, 5), (79, 79), (51, 55), (90, 92), (3, 3), (71, 73), (85, 87), (51, 51), (88, 92), (17, 18), (52, 53), (79, 80), (38, 38), (9, 10), (93, 94), (27, 27), (7, 10), (37, 41), (78, 82), (88, 91), (14, 18), (95, 95), (63, 67), (65, 68), (98, 102), (75, 77), (16, 20), (98, 102), (61, 63), (52, 52), (6, 8), (2, 5), (90, 94), (72, 75), (18, 18), (2, 6), (71, 75), (84, 84), (48, 49), (90, 93), (88, 88), (0, 1), (71, 74), (62, 65), (58, 59), (88, 92), (98, 98), (77, 81), (29, 31), (9, 13), (62, 65), (83, 84), (65, 65), (73, 73), (73, 76), (64, 65), (29, 30), (69, 69), (15, 16), (33, 36), (98, 101), (89, 92), (63, 64), (89, 93), (68, 69), (95, 98), (14, 15), (21, 22), (51, 55), (97, 98), (57, 60), (90, 93), (29, 33), (39, 40), (43, 47), (21, 24), (50, 50), (41, 44), (77, 78), (10, 12), (34, 34), (32, 32), (36, 39), (32, 36), (47, 48), (16, 18), (94, 95), (95, 95), (17, 18), (72, 72), (63, 66), (53, 56), (4, 6), (26, 29), (30, 31), (30, 34), (94, 94), (64, 64), (20, 23), (70, 73), (29, 32), (25, 25), (96, 98), (51, 54), (59, 62), (26, 28), (16, 17), (35, 37), (78, 81), (5, 5), (50, 53), (76, 77), (55, 56), (26, 26), (41, 44), (43, 44), (86, 86), (46, 50), (45, 49), (0, 4), (72, 73), (78, 79), (57, 60), (13, 16), (26, 27), (0, 3), (11, 13), (76, 77), (70, 73), (41, 42), (3, 5), (34, 36), (57, 58), (76, 80), (82, 83), (58, 58), (2, 3), (48, 50), (1, 4), (52, 52), (84, 86), (60, 60), (81, 83), (61, 62), (92, 92), (63, 63), (92, 94), (37, 38), (30, 34), (56, 59), (90, 94), (20, 20), (3, 3), (9, 13), (33, 36), (36, 36), (65, 67), (17, 19), (86, 87), (50, 53), (86, 89), (73, 76), (63, 64), (79, 82), (77, 77), (58, 62), (2, 2), (64, 64), (50, 50), (61, 62), (38, 38), (6, 7), (99, 102), (55, 55), (54, 54), (15, 15), (71, 74), (70, 74), (51, 51), (79, 82), (85, 88), (0, 4), (20, 24), (44, 45), (42, 45), (7, 9), (8, 11), (88, 90), (88, 91), (44, 47), (1, 5), (35, 37), (99, 100), (6, 7), (8, 8), (31, 31), (75, 76), (85, 86), (48, 49), (67, 69), (39, 40), (74, 78), (91, 94), (58, 62), (58, 60), (74, 75), (13, 15), (83, 86), (20, 21), (16, 19), (79, 81), (73, 77), (31, 31), (2, 3), (92, 96), (73, 74), (47, 49), (83, 86), (62, 63), (70, 73), (96, 97), (36, 40), (58, 58), (22, 25), (61, 64), (58, 60), (38, 42), (47, 48), (94, 98), (52, 53), (71, 73), (70, 73), (76, 79), (9, 10), (46, 47), (16, 18), (27, 29), (52, 53), (24, 28), (16, 19), (65, 67), (30, 30), (11, 13), (76, 76), (79, 79), (44, 44), (9, 13), (20, 22), (19, 20), (28, 28), (12, 13), (60, 60), (49, 51), (78, 81), (38, 39), (11, 11), (73, 75), (10, 14), (71, 74), (42, 42), (70, 71), (52, 53), (0, 0), (69, 70), (6, 10), (88, 89), (46, 49), (63, 63), (60, 61), (20, 24), (87, 91), (54, 57), (26, 28), (97, 101), (55, 59), (0, 3), (25, 29), (9, 11), (29, 32), (0, 3), (28, 32), (59, 60), (37, 39), (21, 24), (63, 66), (49, 51), (77, 77), (15, 15), (24, 24), (5, 7), (56, 58), (10, 14), (61, 62), (63, 66), (50, 54), (31, 31), (53, 53), (56, 58), (12, 16), (92, 94), (22, 25), (81, 83), (49, 53), (7, 7), (14, 16), (57, 57), (21, 23), (56, 56), (39, 39), (78, 79), (84, 88), (23, 27), (99, 103), (31, 34), (60, 64), (42, 44), (17, 20), (86, 89), (72, 76), (44, 47), (58, 61), (61, 61), (73, 75), (15, 19), (37, 40), (5, 8), (54, 54), (62, 62), (59, 60), (68, 69), (22, 24), (53, 57), (85, 85), (10, 10), (86, 87), (0, 4), (59, 60), (76, 78), (31, 32), (96, 96), (36, 39), (94, 94), (33, 36), (95, 99), (54, 54), (15, 16), (77, 78), (68, 68), (13, 13), (77, 81), (36, 38), (95, 97), (39, 41), (32, 34), (15, 15), (42, 44), (86, 87), (94, 95), (45, 45), (16, 17), (57, 60), (28, 28), (4, 7), (2, 6), (78, 82), (20, 21), (56, 59), (65, 67), (40, 42), (69, 71), (30, 32), (59, 60), (0, 1), (87, 89), (48, 51), (49, 49), (39, 43), (92, 92), (29, 33), (65, 69), (73, 75), (25, 27), (5, 5), (29, 31), (40, 41), (5, 5), (15, 16), (86,Line truncated
(9, 13), (97, 98), (63, 64), (27, 31), (96, 99), (18, 20), (43, 44), (84, 88), (60, 63), (53, 56), (60, 62), (23, 27), (99, 101), (92, 93), (21, 21), (21, 21), (61, 64), (43, 44), (22, 24), (93, 96), (62, 63), (43, 43), (28, 30), (22, 25), (82, 82), (16, 20), (89, 90), (96, 96), (1, 4), (72, 74), (46, 49), (4, 6), (64, 67), (36, 37), (70, 74), (56, 59), (40, 44), (90, 93), (78, 80), (9, 12), (39, 39), (7, 8), (69, 72), (21, 21), (92, 92), (44, 44), (39, 42), (49, 49), (96, 96), (41, 45), (14, 16), (52, 52), (49, 51), (75, 79), (7, 11), (92, 95), (62, 64), (79, 80), (55, 56), (53, 57), (46, 50), (89, 91), (97, 101), (92, 93), (76, 76), (65, 66), (35, 39), (98, 99), (63, 63), (15, 15), (62, 62), (69, 73), (12, 15), (7, 9), (1, 3), (19, 22), (61, 61), (37, 37), (51, 53), (56, 59), (67, 70), (71, 73), (42, 43), (38, 39), (46, 47), (76, 76), (66, 68), (36, 39), (98, 101), (97, 101), (7, 10), (99, 99), (29, 33), (31, 33), (71, 75), (60, 63), (13, 16), (93, 93), (4, 7), (13, 16), (89, 91), (63, 65), (39, 41), (37, 41), (95, 97), (41, 41), (55, 57), (75, 76), (81, 82), (69, 71), (46, 47), (43, 44), (65, 68), (18, 19), (71, 73), (76, 79), (74, 76), (72, 75), (44, 44), (55, 56), (97, 98), (46, 50), (88, 92), (41, 41), (80, 80), (74, 77), (43, 47), (41, 41), (57, 57), (34, 35), (92, 92), (94, 95), (54, 55), (31, 34), (28, 29), (42, 44), (34, 34), (82, 85), (14, 17), (45, 47), (85, 86), (25, 28), (41, 45), (89, 92), (79, 82), (31, 34), (85, 85), (89, 89), (44, 46), (90, 94), (11, 15), (2, 2), (25, 29), (68, 72), (7, 7), (86, 90), (37, 41), (72, 72), (83, 86), (80, 84), (88, 90), (37, 38), (89, 92), (66, 66), (50, 53), (10, 11), (93, 95), (59, 59), (96, 100), (9, 9), (45, 48), (99, 103), (12, 15), (16, 16), (89, 90), (9, 11), (60, 63), (3, 3), (76, 77), (35, 36), (82, 82), (40, 40), (9, 13), (45, 47), (78, 79), (12, 12), (54, 57), (61, 62), (39, 41), (13, 16), (26, 30), (5, 6), (24, 25), (36, 36), (82, 84), (79, 83), (69, 73), (91, 95), (70, 73), (36, 36), (95, 96), (28, 29), (16, 20), (20, 20), (67, 67), (83, 86), (12, 13), (79, 80), (2, 5), (37, 38), (92, 93), (1, 2), (87, 91), (92, 94), (33, 34), (9, 9), (82, 84), (33, 36), (27, 30), (6, 7), (91, 95), (39, 42), (82, 82), (91, 95), (90, 93), (73, 75), (96, 100), (96, 99), (70, 73), (92, 95), (69, 71), (35, 38), (39, 40), (54, 57), (74, 74), (64, 66), (1, 1), (20, 24), (78, 82), (20, 23), (92, 95), (3, 4), (19, 23), (76, 76), (87, 91), (45, 49), (23, 26), (12, 16), (54, 57), (33, 36), (78, 80), (98, 98), (5, 5), (16, 19), (34, 35), (3, 5), (30, 31), (20, 24), (5, 6), (91, 91), (17, 19), (54, 54), (70, 73), (55, 59), (37, 40), (4, 6), (37, 41), (99, 101), (25, 25), (77, 81), (52, 53), (38, 42), (87, 90), (35, 35), (55, 57), (90, 92), (16, 17), (65, 68), (14, 16), (14, 17), (60, 60), (23, 27), (25, 27), (44, 44), (38, 41), (9, 11), (54, 54), (76, 80), (58, 59), (39, 39), (90, 91), (90, 93), (77, 77), (96, 99), (79, 79), (47, 48), (81, 81), (40, 43), (44, 45), (8, 10), (10, 14), (24, 25), (69, 71), (62, 62), (16, 19), (45, 48), (34, 36), (17, 18), (94, 94), (55, 58), (76, 80), (64, 68), (76, 76), (19, 19), (93, 95), (55, 55), (96, 100), (72, 75), (84, 85), (98, 98), (40, 43), (58, 59), (83, 83), (38, 40), (41, 41), (51, 55), (99, 99), (30, 32), (72, 76), (47, 48), (28, 30), (21, 22), (34, 34), (94, 97), (84, 86), (18, 19), (88, 91), (2, 3), (4, 6), (48, 50), (37, 38), (18, 21), (67, 70), (15, 19), (49, 49), (57, 59), (69, 70), (53, 56), (28, 28), (73, 75), (92, 95), (88, 90), (72, 73), (55, 58), (83, 84), (77, 80), (7, 7), (61, 65), (43, 47), (66, 70), (44, 47), (21, 24), (54, 55), (69, 72), (26, 30), (47, 48), (38, 39), (55, 57), (79, 80), (90, 94), (67, 69), (87, 91), (62, 63), (1, 3), (30, 32), (53, 54), (42, 46), (91, 95), (52, 54), (84, 88), (7, 8), (50, 50), (19, 19), (7, 7), (68, 72), (65, 65), (16, 20), (62, 62), (5, 5), (39, 41), (34, 36), (65, 66), (18, 20), (25, 25), (69, 70), (49, 50), (45, 46), (73, 77), (9, 11), (67, 71), (81, 83), (17, 21), (88, 92), (31, 32), (94, 94), (85, 88), (14, 15), (56, 58), (8, 12), (55, 57), (95, 96), (6, 6), (8, 12), (57, 61), (64, 68), (50, 50), (8, 10), (47, 48), (46, 49), (94, 96), (1, 1), (72, 72), (31, 32), (0, 1), (15, 15), (68, 70), (11, 12), (55, 56), (58, 60), (92, 94), (88, 91), (19, 20), (10, 11), (44, 48), (97, 98), (53, 56), (71, 74), (65, 69), (59, 61), (45, 46), (24, 24), (88, 91), (92, 95), (11, 13), (7, 11), (24, 24), (99, 99), (43, 44), (62, 62), (22, 23), (31, 34), (9, 13), (6, 7), (8, 10), (96, 99), (43, 43), (18, 19), (60, 62), (27, 29), (64, 65), (28, 31), (34, 38), (36, 40), (40, 43), (69, 69), (9, 11), (43, 43), (6, 7), (48, 49), (18, 22), (19, 20), (17, 17), (44, 46), (52, 55), (1, 5), (10, 14), (9, 13), (8, 8), (73, 74), (43, 43), (16, 20), (47, 48), (26, 27), (12, 12), (72, 74), (71, 75), (95, 95), (34, 38), (70, 73), (63, 64), (7, 7), (1, 5), (69, 70), (14, 18), (62, 62), (89, 89), (14, 16), (93, 96), (95, 95), (20, 22), (39, 40), (63, 67), (84, 88), (74, 78), (88, 92), (77, 79), (14, 17), (16, 16Line truncated
(49, 53)`
input = input.split('),')
input = input.map(item => {
item = item.replace('(', '').replace(/\s+/g, '').split(',')
return {
start: Number(item[0]),
end: Number(item[1])
}
})
expect(mergeLintCode(input)).toEqual([{ start: 0, end: 103 }])
})
+17
View File
@@ -0,0 +1,17 @@
import { numIslands } from '../../src/array/number-of-islands'
test('岛屿的个数', () => {
expect(numIslands([
[1, 1, 0, 0, 0],
[0, 1, 0, 0, 1],
[0, 0, 0, 1, 1],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 1]
])).toBe(3)
expect(numIslands([
[1, 1]
])).toBe(1)
expect(numIslands([])).toBe(0)
})
+6
View File
@@ -0,0 +1,6 @@
import partitionArray from '../../src/array/partition-array'
test('loopAscArray', () => {
expect(partitionArray([], 9)).toEqual(0)
expect(partitionArray([3, 2, 2, 1], 2)).toEqual(1)
})
@@ -0,0 +1,15 @@
import removeDuplicates from '../../src/array/remove-duplicates-from-sorted-array'
test('removeDuplicates', () => {
const nums = [1, 1, 2]
expect(removeDuplicates(nums)).toBe(2)
expect(nums).toEqual([1, 2])
})
test('removeDuplicates2', () => {
const nums = [1, 2]
expect(removeDuplicates(nums)).toBe(2)
expect(nums).toEqual([1, 2])
})
+29
View File
@@ -0,0 +1,29 @@
import {
reversePairs,
merge,
mergeSort,
resetCount
} from '../../src/array/reverse-pairs'
describe('逆序对', () => {
beforeEach(() => {
resetCount()
})
test('归并排序 - 合并左右', () => {
expect(merge([7], [5])).toEqual([5, 7])
expect(merge([2], [3])).toEqual([2, 3])
expect(merge([2, 3], [4, 5])).toEqual([2, 3, 4, 5])
})
test('归并排序', () => {
expect(mergeSort([2, 4, 3, 5])).toEqual([2, 3, 4, 5])
expect(mergeSort([2, 4, 3, 0])).toEqual([0, 2, 3, 4])
})
test('逆序对', () => {
expect(reversePairs([7, 5, 6, 4])).toBe(5)
expect(reversePairs([2, 4, 1, 3, 5])).toBe(3)
expect(reversePairs([1, 2, 3, 4])).toBe(0)
})
})
@@ -0,0 +1,6 @@
import { search } from '../../src/array/search-in-rotated-sorted-array'
test('搜索旋转排序数组', () => {
expect(search([4, 5, 6, 7, 0, 1, 2], 0)).toBe(4)
expect(search([4, 5, 6, 7, 0, 1, 2], 3)).toBe(-1)
})
@@ -0,0 +1,8 @@
import searchInsert from '../../src/array/search-insert-position'
test('searchInsert', () => {
expect(searchInsert([1, 3, 5, 6], 5)).toEqual(2)
expect(searchInsert([1, 3, 5, 6], 2)).toEqual(1)
expect(searchInsert([1, 3, 5, 6], 7)).toEqual(4)
expect(searchInsert([1, 3, 5, 6], 0)).toEqual(0)
})
+11
View File
@@ -0,0 +1,11 @@
import selectSort from '../../src/array/select-sort'
test('selectSort', () => {
expect(selectSort([1, 2, 3])).toEqual([1, 2, 3])
expect(selectSort([3, 2, 1])).toEqual([1, 2, 3])
expect(selectSort([])).toEqual([])
expect(selectSort([3, 6, 4, 5, 6, 8])).toEqual([3, 4, 5, 6, 6, 8])
expect(selectSort([1, 1, 1])).toEqual([1, 1, 1])
expect(selectSort([-1, -10, 3])).toEqual([-10, -1, 3])
expect(selectSort([7, 2, 8, 3, 6, 3])).toEqual([2, 3, 3, 6, 7, 8])
})
@@ -0,0 +1,6 @@
import { singleNumbers } from '../../src/array/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof'
test('面试题56 - I. 数组中数字出现的次数', () => {
expect(singleNumbers([4, 1, 4, 6]).some(i => [1, 6].includes(i))).toBe(true)
expect(singleNumbers([1, 2, 10, 4, 1, 4, 3, 3]).some(i => [2, 10].includes(i))).toBe(true)
})
+6
View File
@@ -0,0 +1,6 @@
import { singleNumber } from '../../src/array/single-number'
test('只出现一次的数字', () => {
expect(singleNumber([2, 2, 1])).toBe(1)
expect(singleNumber([4, 1, 2, 1, 2])).toBe(4)
})
+5
View File
@@ -0,0 +1,5 @@
import sortArrayByParity from '../../src/array/sort-array-by-parity'
test('sortArrayByParity', () => {
expect(sortArrayByParity([4, 2, 5, 7])).toEqual([2, 5, 4, 7])
})
@@ -0,0 +1,24 @@
import findSubstring from '../../src/array/substring-with-concatenation-of-all-words'
const str = 'pjzkrkevzztxductzzxmxsvwjkxpvukmfjywwetvfnujhweiybwvvsrfequzkhossmootkmyxgjgfordrpapjuunmqnxxdrqrfgkrsjqbszgiqlcfnrpjlcwdrvbumtotzylshdvccdmsqoadfrpsvnwpizlwszrtyclhgilklydbmfhuywotjmktnwrfvizvnmfvvqfiokkdprznnnjycttprkxpuykhmpchiksyucbmtabiqkisgbhxngmhezrrqvayfsxauampdpxtafniiwfvdufhtwajrbkxtjzqjnfocdhekumttuqwovfjrgulhekcpjszyynadxhnttgmnxkduqmmyhzfnjhducesctufqbumxbamalqudeibljgbspeotkgvddcwgxidaiqcvgwykhbysjzlzfbupkqunuqtraxrlptivshhbihtsigtpipguhbhctcvubnhqipncyxfjebdnjyetnlnvmuxhzsdahkrscewabejifmxombiamxvauuitoltyymsarqcuuoezcbqpdaprxmsrickwpgwpsoplhugbikbkotzrtqkscekkgwjycfnvwfgdzogjzjvpcvixnsqsxacfwndzvrwrycwxrcismdhqapoojegggkocyrdtkzmiekhxoppctytvphjynrhtcvxcobxbcjjivtfjiwmduhzjokkbctweqtigwfhzorjlkpuuliaipbtfldinyetoybvugevwvhhhweejogrghllsouipabfafcxnhukcbtmxzshoyyufjhzadhrelweszbfgwpkzlwxkogyogutscvuhcllphshivnoteztpxsaoaacgxyaztuixhunrowzljqfqrahosheukhahhbiaxqzfmmwcjxountkevsvpbzjnilwpoermxrtlfroqoclexxisrdhvfsindffslyekrzwzqkpeocilatftymodgztjgybtyheqgcpwogdcjlnlesefgvimwbxcbzvaibspdjnrpqtyeilkcspknyylbwndvkffmzuriilxagyerjptbgeqgebiaqnvdubrtxibhvakcyotkfonmseszhczapxdlauexehhaireihxsplgdgmxfvaevrbadbwjbdrkfbbjjkgcztkcbwagtcnrtqryuqixtzhaakjlurnumzyovawrcjiwabuwretmdamfkxrgqgcdgbrdbnugzecbgyxxdqmisaqcyjkqrntxqmdrczxbebemcblftxplafnyoxqimkhcykwamvdsxjezkpgdpvopddptdfbprjustquhlazkjfluxrzopqdstulybnqvyknrchbphcarknnhhovweaqawdyxsqsqahkepluypwrzjegqtdoxfgzdkydeoxvrfhxusrujnmjzqrrlxglcmkiykldbiasnhrjbjekystzilrwkzhontwmehrfsrzfaqrbbxncphbzuuxeteshyrveamjsfiaharkcqxefghgceeixkdgkuboupxnwhnfigpkwnqdvzlydpidcljmflbccarbiegsmweklwngvygbqpescpeichmfidgsjmkvkofvkuehsmkkbocgejoiqcnafvuokelwuqsgkyoekaroptuvekfvmtxtqshcwsztkrzwrpabqrrhnlerxjojemcxel'
const arr = ['dhvf', 'sind', 'ffsl', 'yekr', 'zwzq', 'kpeo', 'cila', 'tfty', 'modg', 'ztjg', 'ybty', 'heqg', 'cpwo', 'gdcj', 'lnle', 'sefg', 'vimw', 'bxcb']
const str2 = 'ejwwmybnorgshugzmoxopwuvshlcwasclobxmckcvtxfndeztdqiakfusswqsovdfwatanwxgtctyjvsmlcoxijrahivwfybbbudosawnfpmomgczirzscqvlaqhfqkithlhbodptvdhjljltckogcjsdbbktotnxgwyuapnxuwgfirbmdrvgapldsvwgqjfxggtixjhshnzphcemtzsvodygbxpriwqockyavfscvtsewyqpxlnnqnvrkmjtjbjllilinflkbfoxdhocsbpirmcbznuioevcojkdqvoraeqdlhffkwqbjsdkfxstdpxryixrdligpzldgtiqryuasxmxwgtcwsvwasngdwovxzafuixmjrobqbbnhwpdokcpfpxinlfmkfrfqrtzkhabidqszhxorzfypcjcnopzwigmbznmjnpttflsmjifknezrneedvgzfmnhoavxqksjreddpmibbodtbhzfehgluuukupjmbbvshzxyniaowdjamlfssndojyyephstlonsplrettspwepipwcjmfyvfybxiuqtkdlzqedjxxbvdsfurhedneauccrkyjfiptjfxmpxlssrkyldfriuvjranikluqtjjcoiqffdxaukagphzycvjtvwdhhxzagkevvuccxccuoccdkbboymjtimdrmerspxpktsmrwrlkvpnhqrvpdekmtpdfuxzjwpvqjjhfaupylefbvbsbhdncsshmrhxoyuejenqgjheulkxjnqkwvzznriclrbzryfaeuqkfxrbldyusoeoldpbwadhrgijeplijcvqbormrqglgmzsprtmryvkeevlthvflsvognbxfjilwkdndyzwwxgdbeqwlldyezmkopktzugxgkklimhhjqkmuaifnodtpredhqygmedtqpezboimeuyyujfjxkdmbjpizpqltvgknnlodtbhnbhjkmuhwxvzgmkhbcvvadhnssbvneecglnqxhavhvxpkjxlluilzpysjcnwguyofnhfvhaceztoiscumkhociglkvispihvyoatxcxbeqsmluixgsliatukrecgoldmzfhwkgaqzsckonjuhxdhqztjfxstjvikdrhpyjfxbjjryslfpqoiphrwfjqqhaamrjbrsiovrxmqsyxhqmritjeauwqbwtpqcqhvyyssvfknfhxvtodpzipueixdbntdfcaeatyyainfpkclbgaaqrwwzwbcjwiqzkwzfuxfclmsxpdyvfbnwxjytnaejivivriamhgqsskqhnqeurttrfrmstrbeokzhuzvbfmwywohmgogyhzpmsdemugqkspsmoppwbnwabdmiruibwznqcuczculujfiavzwynsyqxmarjkshjhxobandwyzggjibjgzyaaqxorqxbkenscbveqbaociwmqxxyzvyblypeongzrttvwqzmrccwkzidyfbxcaypyquodcpwxkstbthuvjqgialhfmgjohzoxvdaxuywfqrgmyahhtpqtazbphmfoluliznftodyguesshcacrsvutylalqrykehjuofisdookjhrljvedsywrlyccpaowjaqyfaqioesxnlkwgpbznzszyudpwrlgrdgwdyhucztsneqttsuirmjriohhgunzatyfrfzvgvptbgpwajgtysligupoqeoqxoyqtzozufvvlktnvahvsseymtpeyfvxttqosgpplkmxwgmsgtpantazppgnubmpwcdqkvhwfuvcahwibniohiqyywnuzzmxeppokxksrfwrpuzqhjgqryorwboxdauhrkxehiwaputeouwxdfoudcoagcxjcuqvenznxxnprgvhasffxtzaxpcfrcovwgrcwqptoekhmgpoywtxruxokcubekzcrqengviwbtgnzvdzrwwkqvacxwgdhffyvjldgvchoiwnfzoyvkiogisdfyjmfomcazigukqlumyzmnzjzhzfpslwsukykwckvktswjdqxdrlsqvsxwxpqkljeyjpulbswwmuhplfueqnvnhukgjarxlxvwmriqjgmxawmndhsvwnjdjvjtxcsjapfogpesxtpypenunfpjuyoevzztctecilqqbxkaqcyhiobvtqgqruumvvhxolbyzsqcrdchhdqprtkkjsccowrjtyjjmkhleanvfpemuublnnyzfabtxsestncfalqenfcswgerbfcqsapzdtscnzugmwlmidtxkvqhbuaecevwhmwkfqmvpgbefpqpsjmdecmixmmbsjxzwvjdmxydechlraajjmoqpcyoqmrjwoiumuzatydzcnktnkeyztoqvogodxxznhvzduzxudwwqhpftwdspuimioanlzobhjakgajafgzxpqckmhdbbnqmcszpuoqbztnftzgahhxwxbgkilnmzfydyxusnnvngksbjabqjaohdvrniezhmxmkxhemwbbclwdxwgngicplzgajmaryzfkyoqlkrmmfirchzrphveuwmvgaxzbwenvteifxuuefnimnadwxhruvoavlzyhfmeasmgrjawongccgfbgoualiaivbhcgvjjnxpggrewglalthmzvgziobrjeanlvyukwlscexbkibvdjhdgnepdiimmkcxhattwglbkicvsfswocbvphmtpwhcgjbnmxgidtlqcnnwtfujhvgzdussqbwynylzvtjapvqtidpdjkpshvrmqlhindhabubyokzdfrwqvnvgzkyhistydagsgnujiviyijdnabfxqbdqnexvwsvzvcsbrmkbkuzsdehghndyqjodnnblfwmaygdstotfkvxozgwhtbhlkvrzismnozqpfthajafuxekzlgigjpsukjvsdihrjzgovnreqwapdkoqswyclqyvbvpedzyoyedvuuamscbxnqnfmmjyehvidnoimmxmtcinwkbqmcobubjjpshucechrqrffqsyscnqoohcsxenypyqhfklloudgmklcejvgynwouzhtfwuuukdbwpmkjrqxeeaipxrokncholathupdetgaktmvmftqjvzyssocftjwemroghrncynmtchhhcaqxbqpthuaafwgrouaxonzocljeuslzsdwvuoodipdpnlhdihaywzmymxdjrqikughquwtenyucjdgrmipiidiwclhuepgyynoslhzahtdqwliktzsddaahohbszhqxxgripqlwlomjbwtuynydoakejmwkvojuwbfltqjfgxqhwkduzbxpdhtpvrzrfjndmsqfizmqxdxtpbpoemekvxzrrakwjxcxqsdasptruqmjtbaapgmkfnbwnlvzlxwdpzfjryanrmzmpzoefapmnsjdgecrdywsabctaegttffigupnwgakylngrrxurtotxqmzxvsqazajvrwsxyeyjteakeudzjxwbjvagnsjntskmocmpgkybqbnwvrwgoskzqkgffpsyhfmxhymqinrbohxlytsmoeleqrjvievpjipsgdkrqeuglrsjnmvdsihicsgkybcjltcswolpsfxdypmlbjotuxewskisnmczfgreuevnjssjifvlqlhkllifxrxkdbjlhcpegmtrelbosyajljvwwedtxbdccpnmreqaqjrxwulpunagwxesbilalrdniqbzxrbpcvmzpyqklsskpwctgqtrjwhrpisocwderqfiqxsdpkphjsapkvhvsqojyixaechvuoemmyqdlfkuzmlliugckuljfkljoshjhlvvlnywvjswvekfyqhjnsusefdtakejxbejrchoncklguqgnyrcslwztbstmycjziuskegagtlonducdogwbevugppsptdqbajmepmmizaycwcgmjeopbivsyphtvxvvgjbyxpgwpganjiaumojpyhhywosrmnouwpstgbrvhtlqcnmqbygbfnabesvshjmdbhyhirfrkqkmfwdgujhzyjdcbyuijjnkqluaczrnrbbwaeeupnwqzbsazplkyaxqorqsshhlljjlpphhedxdepgfgrqerpuhgmaawhnhqwsgnznrfmxjbdrkwjopylxezxgvetcvrwdewsxdeumhzfrvoilmvksuhyqltuimrnsphqslmgvmmojawwptghonigbdclqtbikiacwpjrbxhmzejozpypfixglatdvuogdoizdtsgsztsfcihtgwyqugeuahpuvvzmgarbsyuutmbxuisdfrvbxzxzhmuektssuktoknkfbmcwwubbnwenybmfqglaceuyqnoadzfenjcjfdlvcpiatuhjdujhaffqsvqvuxchgerokejovrqonxxstibunikiedfyahijobxyhimebctobsjudkqstbcxgixgrhpfiofpwruzvpqyjzvollheoldutddnksutjakhtghpxxnjykxjwgqmsvhnykclexepxqxqzghwfxfdhfmflesfabvanxlrurjtigkjotftqnwyskffpxlragrnfffawqtgyfpmzxfpkdpenxlewyxxgrkmwrmshhzfnorolyfxbvdrspxqnxnuoygkruczddgssygfymdcjgvdxutlrhffhnpyjuxmxefrelxezcgikdliyhvpocvvpkvagvmezrxffujeysplvavtjqjxsgujqsjznxforctwzecxyrkwufpdxadrgzczrnyelfschnagucguuqqqwitviynrypsrdswqxqsegulcwrwsjnihxedfcqychqumiscfkwmqqxunqrfbgqjdwmkyelbldxympctbzfupeocwhkypchuyvhybsbmvymjppfrqmlfrbkpjwpyyytytawuuyjrwxboogfessmltwdcssdqtwomymjskujjtmxiueopwacrwfuqazitvyhvlspvoaeipdsjhgyfjbxhitLine truncated
const arr2 = ['toiscumkhociglkvispihvyoatxcx', 'ndojyyephstlonsplrettspwepipw', 'yzfkyoqlkrmmfirchzrphveuwmvga', 'mxxihihnrfbamcyojqpkzodbejtmm', 'fenjcjfdlvcpiatuhjdujhaffqsvq', 'ehghndyqjodnnblfwmaygdstotfkv', 'heoldutddnksutjakhtghpxxnjykx', 'cvrwdewsxdeumhzfrvoilmvksuhyq', 'ftqjvzyssocftjwemroghrncynmtc', 'idiwclhuepgyynoslhzahtdqwlikt', 'eurttrfrmstrbeokzhuzvbfmwywoh', 'jxlluilzpysjcnwguyofnhfvhacez', 'uskegagtlonducdogwbevugppsptd', 'xmcxwufajmnveuwuoyosqnoqwvtjk', 'wolpsfxdypmlbjotuxewskisnmczf', 'fjryanrmzmpzoefapmnsjdgecrdyw', 'jgmxawmndhsvwnjdjvjtxcsjapfog', 'wuhkzghvmjhawcfszbhzrbpgsidnb', 'yelbldxympctbzfupeocwhkypchuy', 'vzduzxudwwqhpftwdspuimioanlzo', 'bdpdeofidldoymakfnpgekmsltcrr', 'fmyeodowglzyjzuhencufcwdobyds', 'dhtypunakzituezjyhbrpuksbamui', 'bdmiruibwznqcuczculujfiavzwyn', 'eudzjxwbjvagnsjntskmocmpgkybq', 'tuynydoakejmwkvojuwbfltqjfgxq', 'psrdswqxqsegulcwrwsjnihxedfcq', 'cokfdmtsgboidkpgpnmdeyhawkqqs', 'fujhvgzdussqbwynylzvtjapvqtid', 'rqeuglrsjnmvdsihicsgkybcjltcs', 'vhybsbmvymjppfrqmlfrbkpjwpyyy', 'aukagphzycvjtvwdhhxzagkevvucc', 'hwkduzbxpdhtpvrzrfjndmsqfizmq', 'ywnuzzmxeppokxksrfwrpuzqhjgqr', 'qbajmepmmizaycwcgmjeopbivsyph', 'uamscbxnqnfmmjyehvidnoimmxmtc', 'nxvspywfggjrmxryybdltmsfykstm', 'amrjbrsiovrxmqsyxhqmritjeauwq', 'yorwboxdauhrkxehiwaputeouwxdf', 'qkewycsdjglkiwaacdqterkixkgra', 'ycngvlvpyvczfxvlwhjgicvempfob', 'jgphsxzzqlvujkwwgiodbfjesnbsb', 'mkxhemwbbclwdxwgngicplzgajmar', 'mryvkeevlthvflsvognbxfjilwkdn', 'mezrxffujeysplvavtjqjxsgujqsj', 'rtotxqmzxvsqazajvrwsxyeyjteak', 'sabctaegttffigupnwgakylngrrxu', 'xccuoccdkbboymjtimdrmerspxpkt', 'xusnnvngksbjabqjaohdvrniezhmx', 'oyuejenqgjheulkxjnqkwvzznricl', 'mxszcosgovisnbemrjlndqwkvhqso', 'wsgnznrfmxjbdrkwjopylxezxgvet', 'dxmisfskvevpcnujqxrqedleuyowk', 'dhrgijeplijcvqbormrqglgmzsprt', 'vuxchgerokejovrqonxxstibuniki', 'lumyzmnzjzhzfpslwsukykwckvkts', 'inwkbqmcobubjjpshucechrqrffqs', 'ywtxruxokcubekzcrqengviwbtgnz', 'ccpnmreqaqjrxwulpunagwxesbila', 'pesxtpypenunfpjuyoevzztctecil', 'sygfymdcjgvdxutlrhffhnpyjuxmx', 'uisdfrvbxzxzhmuektssuktoknkfb', 'cejvgynwouzhtfwuuukdbwpmkjrqx', 'oudcoagcxjcuqvenznxxnprgvhasf', 'sxnlkwgpbznzszyudpwrlgrdgwdyh', 'qqbxkaqcyhiobvtqgqruumvvhxolb', 'mkhleanvfpemuublnnyzfabtxsest', 'bibaxwnriowoavosminabvfxastkc', 'bcxgixgrhpfiofpwruzvpqyjzvoll', 'lzccnsztxfyqhqyhkuppapvgvdtkm', 'pdjkpshvrmqlhindhabubyokzdfrw', 'qbbnhwpdokcpfpxinlfmkfrfqrtzk', 'rnyelfschnagucguuqqqwitviynry', 'qtrjwhrpisocwderqfiqxsdpkphjs', 'vxttqosgpplkmxwgmsgtpantazppg', 'tyisidnhlksfznubucqxwaheamndj', 'kgaqzsckonjuhxdhqztjfxstjvikd', 'jeuslzsdwvuoodipdpnlhdihaywzm', 'vdzrwwkqvacxwgdhffyvjldgvchoi', 'cftbefxgasawzagfugmuthjahylkh', 'xraytcolbhkiiasaazkvqzvfxbaax', 'oyqtzozufvvlktnvahvsseymtpeyf', 'rnnujgyjugrzjoefmghjfhcrnbrtg', 'rfzvgvptbgpwajgtysligupoqeoqx', 'igbdclqtbikiacwpjrbxhmzejozpy', 'dyzwwxgdbeqwlldyezmkopktzugxg', 'hmetreydbcstkwoexwsfhfekfvfpl', 'zcnftuzrvzjjudsgcqmmfpnmyrenu', 'zzmvkskzeglxaqrrvmrgcwcnvkhwz', 'vjswvekfyqhjnsusefdtakejxbejr', 'rwwzwbcjwiqzkwzfuxfclmsxpdyvf', 'fdbdychmupcsxvhazvrihhnxfyumo', 'vdtevyducpdksntgyaqtkrrkwiyuh', 'nbvqeyoghccxfuwacxzxqkezxefxa', 'vpgbefpqpsjmdecmixmmbsjxzwvjd', 'jwgqmsvhnykclexepxqxqzghwfxfd', 'olyfxbvdrspxqnxnuoygkruczddgs', 'qgmxtdfoiaakorebqpbbpegawrqym', 'liaivbhcgvjjnxpggrewglalthmzv', 'choncklguqgnyrcslwztbstmycjzi', 'fpkdpenxlewyxxgrkmwrmshhzfnor', 'hhhcaqxbqpthuaafwgrouaxonzocl', 'ipahojoysepzhpljpaugrghgjimtd', 'wosrmnouwpstgbrvhtlqcnmqbygbf', 'nwyskffpxlragrnfffawqtgyfpmzx', 'bcvvadhnssbvneecglnqxhavhvxpk', 'hoavxqksjreddpmibbodtbhzfehgl', 'lazxadnftllhmjslfbrtdlahkgwle', 'uuukupjmbbvshzxyniaowdjamlfss', 'tpqtazbphmfoluliznftodyguessh', 'ychqumiscfkwmqqxunqrfbgqjdwmk', 'rkdclgzjvqrjofjjvbyfragofeoaz', 'pphhedxdepgfgrqerpuhgmaawhnhq', 'cacrsvutylalqrykehjuofisdookj', 'kyldfriuvjranikluqtjjcoiqffdx', 'bnwvrwgoskzqkgffpsyhfmxhymqin', 'uzmlliugckuljfkljoshjhlvvlnyw', 'abfxqbdqnexvwsvzvcsbrmkbkuzsd', 'xotbbyvxyovzxgtcyzgqnsvcfhczo', 'bwtpqcqhvyyssvfknfhxvtodpzipu', 'nsfbpjqkijvudpriqrfsrdfortimg', 'tgwyqugeuahpuvvzmgarbsyuutmbx', 'upnwqzbsazplkyaxqorqsshhlljjl', 'edfyahijobxyhimebctobsjudkqst', 'ialhfmgjohzoxvdaxuywfqrgmyahh', 'jlhcpegmtrelbosyajljvwwedtxbd', 'tpfppjzowoltyqijfoabgzejerpat', 'mgogyhzpmsdemugqkspsmoppwbnwa', 'nubmpwcdqkvhwfuvcahwibniohiqy', 'ukfadjvdnrievszilfinxbyrvknfi', 'dgnepdiimmkcxhattwglbkicvsfsw', 'syqxmarjkshjhxobandwyzggjibjg', 'bnwxjytnaejivivriamhgqsskqhnq', 'hzyjdcbyuijjnkqluaczrnrbbwaee', 'yscnqoohcsxenypyqhfklloudgmkl', 'habidqszhxorzfypcjcnopzwigmbz', 'wjdqxdrlsqvsxwxpqkljeyjpulbsw', 'tytawuuyjrwxboogfessmltwdcssd', 'pfixglatdvuogdoizdtsgsztsfcih', 'apkvhvsqojyixaechvuoemmyqdlfk', 'ouaehwnnxwkdplodpuqxdbemfwahp', 'ixuckaralemvsnbgooorayceuedto', 'ymxdjrqikughquwtenyucjdgrmipi', 'smrwrlkvpnhqrvpdekmtpdfuxzjwp', 'bhjakgajafgzxpqckmhdbbnqmcszp', 'beqsmluixgsliatukrecgoldmzfhw', 'greuevnjssjifvlqlhkllifxrxkdb', 'yzsqcrdchhdqprtkkjsccowrjtyjj', 'sviyovhitxeajqahshpejaqtcdkuv', 'qtwomymjskujjtmxiueopwacrwfuq', 'mzyjtctvtwgyiesxhynvogxnjdjph', 'dLine truncated
const str3 = 'ababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababaLine truncated
const arr3 = ['ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba', 'ab', 'ba']
test('串联所有单词的子串', () => {
expect(findSubstring('', [])).toEqual([])
expect(findSubstring('abaababbaba', ['ba', 'ab', 'ab'])).toEqual([1, 3])
expect(findSubstring('foobarfoobar', ['foo', 'bar'])).toEqual([0, 3, 6])
expect(findSubstring('barfoothefoobarman', ['foo', 'bar'])).toEqual([0, 9])
expect(findSubstring('wordgoodgoodgoodbestword', ['word', 'good', 'best', 'word'])).toEqual([])
expect(findSubstring('wordgoodstudentgoodword', ['word', 'student'])).toEqual([])
expect(findSubstring('abababab', ['a', 'b'])).toEqual([0, 1, 2, 3, 4, 5, 6])
expect(findSubstring('abababab', ['ab', 'ab', 'ab'])).toEqual([0, 2])
expect(findSubstring(str, arr)).toEqual([935])
expect(findSubstring(str2, arr2)).toEqual([373])
expect(findSubstring(str3, arr3)).toEqual([])
})
@@ -0,0 +1,10 @@
import hasGroupsSizeX from '../../src/array/x-of-a-kind-in-a-deck-of-cards'
test('hasGroupsSizeX', () => {
expect(hasGroupsSizeX([1, 2, 3, 4, 4, 3, 2, 1])).toEqual(true)
expect(hasGroupsSizeX([1, 1, 1, 2, 2, 2, 3, 3])).toEqual(false)
expect(hasGroupsSizeX([1, 1, 2, 2, 2, 2])).toEqual(true)
expect(hasGroupsSizeX([1])).toEqual(false)
expect(hasGroupsSizeX([1, 1])).toEqual(true)
expect(hasGroupsSizeX([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10])).toEqual(true)
})
+12
View File
@@ -0,0 +1,12 @@
import { getPrimes, nthSuperUglyNumber } from '../../src/heap/super-ugly-number'
test('计算质因数', () => {
expect(getPrimes(6)).toEqual([2, 3])
expect(getPrimes(4)).toEqual([2])
expect(getPrimes(180)).toEqual([2, 3, 5])
})
// test('superUglyNumber', () => {
// expect(nthSuperUglyNumber(12, [2, 7, 13, 19])).toBe(32)
// expect(nthSuperUglyNumber(800, [37, 43, 59, 61, 67, 71, 79, 83, 89, 97, 101, 103, 113, 127, 131, 157, 163, 167, 173, 179, 191, 193, 197, 199, 211, 229, 233, 239, 251, 257])).toBe(32)
// })
+62
View File
@@ -0,0 +1,62 @@
import { merge, mergeKLists } from '../../src/list/merge-k-sorted-lists'
function ListNode (val) {
this.val = val
this.next = null
}
const arr2List = (arr) => {
let first = null
let res = null
for (let n = 0, len = arr.length; n < len; n++) {
const tmp = new ListNode(arr[n])
if (res) res.next = tmp
else first = tmp
res = tmp
}
return first
}
test('数组转链表', () => {
expect(arr2List([1, 2, 3])).toEqual({ next: { next: { next: null, val: 3 }, val: 2 }, val: 1 })
})
test('合并俩链表', () => {
const source1 = arr2List([1, 4, 5])
const source2 = arr2List([1, 3, 4])
const out = [1, 1, 3, 4, 4, 5]
expect(merge(source1, source2)).toEqual(arr2List(out))
})
test('合并K个排序链表 - 1', () => {
const source = [
arr2List([1, 4, 5]),
arr2List([1, 3, 4]),
arr2List([2, 6])
]
const out = [1, 1, 2, 3, 4, 4, 5, 6]
expect(mergeKLists(source)).toEqual(arr2List(out))
})
test('合并K个排序链表 - 2', () => {
const source = [
arr2List([2, 4, null]),
arr2List([null]),
arr2List([-1, null])
]
const out = [-1, 2, 4, null]
expect(mergeKLists(source)).toEqual(arr2List(out))
})
test('合并K个排序链表 - 3', () => {
const source = [
arr2List([2, 6, null]),
arr2List([5, null]),
arr2List([7, null])
]
const out = [2, 5, 6, 7, null]
expect(mergeKLists(source)).toEqual(arr2List(out))
})
+6
View File
@@ -0,0 +1,6 @@
import { waysToChange } from '../../src/math/coin-lcci'
test('硬币', () => {
expect(waysToChange(5)).toBe(2)
expect(waysToChange(10)).toBe(4)
})
@@ -0,0 +1,6 @@
import trailingZeroes from '../../src/math/factorial-trailing-zeroes'
test('trailingZeroes', () => {
expect(trailingZeroes(3)).toBe(0)
expect(trailingZeroes(5)).toBe(1)
})
+12
View File
@@ -0,0 +1,12 @@
import { permute } from '../../src/math/permutations'
test('全排列', () => {
expect(permute([1, 2, 3])).toEqual([
[1, 2, 3],
[1, 3, 2],
[2, 1, 3],
[2, 3, 1],
[3, 1, 2],
[3, 2, 1]
])
})
+7
View File
@@ -0,0 +1,7 @@
import { nthUglyNumber } from '../../src/math/ugly-number-ii.js'
test('丑数 II', () => {
expect(nthUglyNumber(9)).toBe(10)
expect(nthUglyNumber(1)).toBe(1)
expect(nthUglyNumber(10)).toBe(12)
})
+42
View File
@@ -0,0 +1,42 @@
import { maximalRectangle } from '../../src/stack/maximal-rectangle'
test('maximalRectangle', () => {
expect(maximalRectangle([
['1', '0', '1', '0', '0'],
['1', '0', '1', '1', '1'],
['1', '1', '1', '1', '1'],
['1', '0', '0', '1', '0']
])).toBe(6)
expect(maximalRectangle([
[1, 1, 0, 0, 1],
[0, 1, 0, 0, 1],
[0, 0, 1, 1, 1],
[0, 0, 1, 1, 1],
[0, 0, 0, 0, 1]
])).toBe(6)
expect(maximalRectangle([
[true, true, false, false, true],
[false, true, false, false, true],
[false, false, true, true, true],
[false, false, true, true, true],
[false, false, false, false, true]
])).toBe(6)
expect(maximalRectangle([
[0, 0],
[0, 0]
])).toBe(0)
expect(maximalRectangle([['1']])).toBe(1)
expect(maximalRectangle([['0', '1']])).toBe(1)
expect(maximalRectangle([['1', '1']])).toBe(2)
expect(maximalRectangle([['1', '1', '1', '1']])).toBe(4)
expect(maximalRectangle([[1], [0], [1], [1], [1], [1], [0]])).toBe(4)
expect(maximalRectangle([[1], [0], [1], [1], [1], [1], [1], [0]])).toBe(5)
expect(maximalRectangle([['0', '1'], ['1', '0']])).toBe(1)
expect(maximalRectangle([['0', '1'], ['0', '1']])).toBe(2)
expect(maximalRectangle([['1', '0'], ['1', '0']])).toBe(2)
expect(maximalRectangle([['0', '0', '0'], ['0', '0', '0'], ['1', '1', '1']])).toBe(3)
})
+7
View File
@@ -0,0 +1,7 @@
import { compareStrings } from '../../src/string/compare-strings'
test('比较字符串', () => {
expect(compareStrings('ABCD', 'AB')).toBe(true)
expect(compareStrings('ABCD', 'ACD')).toBe(true)
expect(compareStrings('ABCD', 'AABC')).toBe(false)
})
+7
View File
@@ -0,0 +1,7 @@
import { containsDuplicate } from '../../src/string/contains-duplicate'
test('存在重复元素', () => {
expect(containsDuplicate([1, 2, 3, 1])).toBe(true)
expect(containsDuplicate([1, 2, 3, 4])).toBe(false)
expect(containsDuplicate([1, 1, 1, 3, 3, 4, 3, 2, 4, 2])).toBe(true)
})
@@ -0,0 +1,9 @@
import CountBinarySubstrings from '../../src/string/count-binary-substrings'
test('CountBinarySubstrings', () => {
expect(CountBinarySubstrings('00110011')).toBe(6)
})
test('CountBinarySubstrings2', () => {
expect(CountBinarySubstrings('11001111101101100111111111111100110010111111111001101111111111010100100111100011111101111011111101011101000011110011100111010110001110111010111111101011001011111101011011011111110011111110000111101101011111111110101010011111000100000010011010011001011111101101111101111110100110011101111011100010111001100110100010111000000011010000111001111110101101011101100000111101101111010101100101011111010111111111111101001101011111011110011010111011111111111001110110110100101101111111011100110111111111100011101100001011111111111011100111110111000101111100111101111111101110001101010111011010111010110111000111011011111101110001111101011001101111110011111101111111011011100111011101111101111111010011111001110101110111100110111001011001010101100010111001101111011111101111111111100101011001001111101010111110101011011011111101111110110110010011110011110001110101111001001100111111111001001111000111110111000010011011110110111100101011100011110100000011111100010110001101101111110001100011101011001111111000111001010001110111011100111111111110111111011111100111101111011100111111011101111101111111011111010110101111101100110111011011111000010001010101101101110111111101111111001101110110011110111000110111001010101111111111011100101011010011110111101110111100110000001101111111111011110101100100101111111001111101110001011110101110111111111110000010111110111101111111111111001001000011011011111100100001111010011111111010110100111100110111110001110100000101100110110110111111111100111111011000101110110101110111111111101011101010011011000101111110011010110111110010001010111110111110111101101011111110110111101011110010101100011010110001101100111111011001111101001011110110010001111111101001111011001011111110101101100111100100101110101111111011111011111010011100111011111100011101110100110111011111000111111111010101011010111111111001101111001111011101100101101111000111110101100111111011011010001101100010100011110111001001111111110111110111111111001011110011111100110100100101111111101100010011011111100111110101100111011111101100100000011111110001101111011011110101111100010111000111110111001000001111110110110100101001101010110011111111011110101111110001011100010111110101101101111111111111011010111000001101010011110101101111000110111101001101111111111111111000110110111100110100111001111111111101101110011101001101110100101101111111111111111100011011110111111101110100011011101111101001111101111111101101111111110111110000001011011011110110111111111111110111110001011111111011111111111111111111111001001110000110100010001101101101111111101011110001101001000011110111001111110101001011010101000001110011111010110011111101110111110110101111110111110110101001110111100010000101111101101111101110110110100010101011011111111011111000100101111011000001101001011110101001111011101110111010011011011110011101111011011111010001101101101111011110110111010100011110100111111101110110111000011111111111110001110101010011100101000110110111011110101111100111110101011010101011111100101011110101110011100000111101000111101101111010011100111011101101011111110001011110101111101111100011111101001000011010100010111111100101101100001011111101101111010001011110111110110011000001111111111010100101001111001111101111000111111011110111111001111100001011110111010010011110011011101001001011011110011111111110001101111111010101100110100100110010001111000101001111110011011111100111110001111010111011111101011111011110101101111111011110111111111111000011011001101100111111111011111111010110100101101100111010001111011111101111110111111111101100111000011111100011110111001111111010111111101001100001100110010111110010011101110111101011011010110110110100111101110111001010110110011100010011010110101110000011010111111111010110011110010011000011111101010011111110111000001111001101010100101111011101110111110101101011111011001111111100110111010111011111100110001101110101100111111111111001110111011110111111011111100111010111001011001001111111111110110111001111111111001011111110011110101000110111110010000101111011111110111111001111101110101011111110111110110100001100101110110110001111110110100001110010101011111010111110101111000110010111101110111011100010001111111111001011001100110110111101111110001000101111110111101001110101111111110010111111111110011111101100100110011111001110111100111110001011011111001100110000101001101111011001111101111011110111111001100110111110110011010101111111110101111111001011010111111110111000011110110111111110111111100101001100000000110000101110111011111011111111011011110010111110101101101010111000011101001010011110011110111011010100110101101111011111101011011111001101111011111111010100001010100100011101110001101011011001011111011010111001011110111111011110111101000010111101101111111110110001111110011110101110110101110001011100110101100101111111011111111101110111110101101111110010101110011101101010110001111100000100011011111110000110101101111000101111100100011100111110011101010010001001110111100001001111011011110100111010110101011010000111111110111Line truncated
})
@@ -0,0 +1,12 @@
import regularExpressionMatching from '../../src/string/regular-expression-matching'
test('regularExpressionMatching', () => {
expect(regularExpressionMatching('aa', 'a')).toEqual(false)
expect(regularExpressionMatching('aaa', 'aa')).toEqual(false)
expect(regularExpressionMatching('aa', 'aa')).toEqual(true)
expect(regularExpressionMatching('aa', 'a*')).toEqual(true)
expect(regularExpressionMatching('ab', '.*')).toEqual(true)
expect(regularExpressionMatching('aab', 'c*a*b')).toEqual(true)
expect(regularExpressionMatching('mississippi', 'mis*is*p*.')).toEqual(false)
expect(regularExpressionMatching('mississippi', 'mis*is*ip*.')).toEqual(true)
})
Loaded 100 of 106 files, more files were not shown because too many files have changed in this diff. Show more