diff --git a/2vYnGI/index.ts b/2vYnGI/index.ts index 8ab948a9..7e00e316 100644 --- a/2vYnGI/index.ts +++ b/2vYnGI/index.ts @@ -1,7 +1,7 @@ export default function breakfastNumber( staple: number[], drinks: number[], - x: number + x: number, ): number { staple.sort((a, b) => a - b); drinks.sort((a, b) => a - b); diff --git a/3sum-closest/index.ts b/3sum-closest/index.ts index 1c8fb694..cbc560cf 100644 --- a/3sum-closest/index.ts +++ b/3sum-closest/index.ts @@ -1,6 +1,6 @@ export default function threeSumClosest( nums: number[], - target: number + target: number, ): number { const N = nums.length; let res = Number.MAX_SAFE_INTEGER; diff --git a/4sum/index.ts b/4sum/index.ts index 8ff376ac..20e66558 100644 --- a/4sum/index.ts +++ b/4sum/index.ts @@ -12,8 +12,8 @@ function fourSum(nums: number[], target: number): number[][] { let left: number = j + 1; let right: number = nums.length - 1; while (left < right) { - const res: number = - nums[i] + nums[j] + nums[left] + nums[right]; + const res: number = nums[i] + nums[j] + nums[left] + + nums[right]; if (res > target) { right--; } else if (res < target) { diff --git a/4ueAj6/index.ts b/4ueAj6/index.ts index 446a2801..b1956982 100644 --- a/4ueAj6/index.ts +++ b/4ueAj6/index.ts @@ -2,7 +2,7 @@ import { ListNode as Node } from "../reverse-linked-list/ListNode.ts"; export default function insert( head: Node | null, - insertVal: number + insertVal: number, ): Node | null { if (!head) { const node = new Node(insertVal); diff --git a/FJxjiD/index.ts b/FJxjiD/index.ts index e11bfbfc..03e8a58b 100644 --- a/FJxjiD/index.ts +++ b/FJxjiD/index.ts @@ -16,16 +16,16 @@ export default function chickenCoolRun(paths: number[][]): number { temp[1] = Math.min( temp[1], temp[0] < Infinity ? temp[0] + 1 : Infinity, - temp[2] < Infinity ? temp[2] + 1 : Infinity + temp[2] < Infinity ? temp[2] + 1 : Infinity, ); temp[0] = Math.min( temp[0], - paths[0][j] === 0 ? temp[1] + 1 : Infinity + paths[0][j] === 0 ? temp[1] + 1 : Infinity, ); temp[2] = Math.min( temp[2], - paths[2][j] === 0 ? temp[1] + 1 : Infinity + paths[2][j] === 0 ? temp[1] + 1 : Infinity, ); } diff --git a/Jf1JuT/index.ts b/Jf1JuT/index.ts index a8a93e29..74d59585 100644 --- a/Jf1JuT/index.ts +++ b/Jf1JuT/index.ts @@ -61,7 +61,7 @@ function createEdgesAndIndegrees(words: string[]): { function topologicalsort( edges: Map>, indegrees: Map, - chars: Set + chars: Set, ): string[] { const order: string[] = []; diff --git a/KnLfVT/index.ts b/KnLfVT/index.ts index cc741464..5452131c 100644 --- a/KnLfVT/index.ts +++ b/KnLfVT/index.ts @@ -1,15 +1,15 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function expandBinaryTree( - root: TreeNode | null + root: TreeNode | null, ): TreeNode | null { return root ? new TreeNode( - root.val, - root.left ? new TreeNode(-1, expandBinaryTree(root.left)) : null, - root.right - ? new TreeNode(-1, null, expandBinaryTree(root.right)) - : null - ) + root.val, + root.left ? new TreeNode(-1, expandBinaryTree(root.left)) : null, + root.right + ? new TreeNode(-1, null, expandBinaryTree(root.right)) + : null, + ) : null; } diff --git a/NyZD2B/index.ts b/NyZD2B/index.ts index bc102256..089b9f6a 100644 --- a/NyZD2B/index.ts +++ b/NyZD2B/index.ts @@ -15,7 +15,7 @@ class VendingMachine { number: number, item: string, price: number, - duration: number + duration: number, ): void { const good = this.#item2good.get(item) ?? [ new AvlTree((a, b) => @@ -71,7 +71,7 @@ class VendingMachine { cost += value.price * diff; } }, - signal + signal, ); toBeRemoved.forEach((n) => tree.remove(n)); diff --git a/QO5KpG/index.ts b/QO5KpG/index.ts index ab1c8a80..6f13937d 100644 --- a/QO5KpG/index.ts +++ b/QO5KpG/index.ts @@ -4,7 +4,7 @@ import { lowerBound } from "../number-of-pairs-satisfying-inequality/lowerBound. export default function getNumber( root: TreeNode | null, - ops: number[][] + ops: number[][], ): number { const sorted = inorderTraversal(root); let ans = 0; diff --git a/U7WvvU/index.ts b/U7WvvU/index.ts index 78758bdb..cdf57c73 100644 --- a/U7WvvU/index.ts +++ b/U7WvvU/index.ts @@ -29,7 +29,7 @@ export default function closeLampInTree(root: TreeNode | null): number { open + 1, close + 1, self + 3, - notSelf + 1 + notSelf + 1, ); } @@ -41,7 +41,7 @@ export default function closeLampInTree(root: TreeNode | null): number { open + 1, close + 1, self + 1, - notSelf + 3 + notSelf + 3, ); } else { allClose = Math.min( @@ -49,7 +49,7 @@ export default function closeLampInTree(root: TreeNode | null): number { open + 2, close, self + 2, - notSelf + 2 + notSelf + 2, ); } @@ -60,7 +60,7 @@ export default function closeLampInTree(root: TreeNode | null): number { open + 2, close, self + 2, - notSelf + 2 + notSelf + 2, ); } else { // 关着 @@ -69,7 +69,7 @@ export default function closeLampInTree(root: TreeNode | null): number { open + 1, close + 1, self + 1, - notSelf + 3 + notSelf + 3, ); } @@ -81,7 +81,7 @@ export default function closeLampInTree(root: TreeNode | null): number { open + 1, close + 1, self + 3, - notSelf + 1 + notSelf + 1, ); } else { justNotSelf = Math.min( @@ -89,7 +89,7 @@ export default function closeLampInTree(root: TreeNode | null): number { open, close + 2, self + 2, - notSelf + 2 + notSelf + 2, ); } diff --git a/ZbAuEH/index.ts b/ZbAuEH/index.ts index 9bec41b1..aea91a7e 100644 --- a/ZbAuEH/index.ts +++ b/ZbAuEH/index.ts @@ -23,7 +23,7 @@ function getMaximumNumber(moles: number[][]): number { for (let cnt = 0, j = i - 1; cnt < 10 && j >= 0; j--, cnt++) { if ( Math.abs(x - moles[j][1]) + Math.abs(y - moles[j][2]) <= - t - moles[j][0] + t - moles[j][0] ) { dp[i][1] = Math.max(dp[i][1], dp[j][1] + 1); } diff --git a/add-binary/index.ts b/add-binary/index.ts index 75237984..a2691b36 100644 --- a/add-binary/index.ts +++ b/add-binary/index.ts @@ -3,8 +3,7 @@ export default function addBinary(num1: string, num2: string): string { let carry = 0; for (let i = 0; i < Math.max(num2.length, num1.length); i++) { // console.log(i, num1[i], num2[i], carry); - const r = - carry + + const r = carry + Number(getIntegerReverse(num1, i)) + Number(getIntegerReverse(num2, i)); result.push(r % 2); diff --git a/add-one-row-to-tree/index.ts b/add-one-row-to-tree/index.ts index de07b88e..eadd7a9a 100644 --- a/add-one-row-to-tree/index.ts +++ b/add-one-row-to-tree/index.ts @@ -3,7 +3,7 @@ import { TreeNode } from "../mod.ts"; export default function addOneRow( root: TreeNode | null, val: number, - depth: number + depth: number, ): TreeNode | null { if (!root || !depth) return null; @@ -13,13 +13,13 @@ export default function addOneRow( return new TreeNode( root.val, new TreeNode(val, root.left), - new TreeNode(val, null, root.right) + new TreeNode(val, null, root.right), ); } return new TreeNode( root.val, addOneRow(root.left, val, depth - 1), - addOneRow(root.right, val, depth - 1) + addOneRow(root.right, val, depth - 1), ); } diff --git a/add-two-numbers-ii/index.ts b/add-two-numbers-ii/index.ts index 01c8437b..0dbc81e4 100644 --- a/add-two-numbers-ii/index.ts +++ b/add-two-numbers-ii/index.ts @@ -2,7 +2,7 @@ import { ListNode } from "../mod.ts"; export default function addTwoNumbers( l1: ListNode | null, - l2: ListNode | null + l2: ListNode | null, ): ListNode | null { if (!l1) { return l2; diff --git a/add-two-polynomials-represented-as-linked-lists/index.ts b/add-two-polynomials-represented-as-linked-lists/index.ts index 7ae114fa..c03be5e7 100644 --- a/add-two-polynomials-represented-as-linked-lists/index.ts +++ b/add-two-polynomials-represented-as-linked-lists/index.ts @@ -2,7 +2,7 @@ import { PolyNode } from "./PolyNode.ts"; export default function addPoly( poly1: PolyNode | null, - poly2: PolyNode | null + poly2: PolyNode | null, ): PolyNode | null { const dummy = new PolyNode(); let node = dummy; diff --git a/adding-two-negabinary-numbers/index.ts b/adding-two-negabinary-numbers/index.ts index 437eaa46..bf88b039 100644 --- a/adding-two-negabinary-numbers/index.ts +++ b/adding-two-negabinary-numbers/index.ts @@ -1,6 +1,6 @@ export default function addNegabinary( arr1: number[], - arr2: number[] + arr2: number[], ): number[] { const len = Math.max(arr1.length, arr2.length); arr1 = arr1.reverse(); diff --git a/advantage-shuffle/index.ts b/advantage-shuffle/index.ts index 08a68630..22c01bd9 100644 --- a/advantage-shuffle/index.ts +++ b/advantage-shuffle/index.ts @@ -1,6 +1,6 @@ export default function advantageCount( nums1: number[], - nums2: number[] + nums2: number[], ): number[] { const n = nums1.length; const idx1: number[] = new Array(n).fill(0); diff --git a/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period/index.ts b/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period/index.ts index 1a34e27e..edf2916d 100644 --- a/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period/index.ts +++ b/alert-using-same-key-card-three-or-more-times-in-a-one-hour-period/index.ts @@ -1,6 +1,6 @@ export default function alertNames( keyName: string[], - keyTime: string[] + keyTime: string[], ): string[] { const map = new Map(); @@ -21,7 +21,7 @@ export default function alertNames( v.length >= 3 && v .sort((a, b) => a - b) - .some((n, i, a) => i + 2 < a.length && 60 >= a[i + 2] - n) + .some((n, i, a) => i + 2 < a.length && 60 >= a[i + 2] - n), ) .map((a) => a[0]) .sort(); diff --git a/all-elements-in-two-binary-search-trees/index.ts b/all-elements-in-two-binary-search-trees/index.ts index 7d3dfe99..41cf75c4 100644 --- a/all-elements-in-two-binary-search-trees/index.ts +++ b/all-elements-in-two-binary-search-trees/index.ts @@ -4,7 +4,7 @@ import { merge_sort } from "./merge_sort.ts"; export default function getAllElements( root1: TreeNode | null, - root2: TreeNode | null + root2: TreeNode | null, ): number[] { const nums1: number[] = []; const nums2: number[] = []; diff --git a/all-paths-from-source-to-target/index.ts b/all-paths-from-source-to-target/index.ts index 0eb2cab1..6933513e 100644 --- a/all-paths-from-source-to-target/index.ts +++ b/all-paths-from-source-to-target/index.ts @@ -7,7 +7,7 @@ function dfs( graph: number[][], res: number[][], index: number, - path: number[] + path: number[], ) { if (index === graph.length - 1) { res.push(Array.from(path)); diff --git a/apply-discount-to-prices/index.ts b/apply-discount-to-prices/index.ts index ee90ebca..a5af758d 100644 --- a/apply-discount-to-prices/index.ts +++ b/apply-discount-to-prices/index.ts @@ -1,6 +1,6 @@ export default function discountPrices( sentence: string, - discount: number + discount: number, ): string { return sentence .split(" ") diff --git a/armstrong-number/index.ts b/armstrong-number/index.ts index e95f6d15..acd04eee 100644 --- a/armstrong-number/index.ts +++ b/armstrong-number/index.ts @@ -2,7 +2,7 @@ export default function isArmstrong(n: number) { return ( [...n.toString()].reduce( (p, v, _i, a) => p + Math.pow(Number(v), a.length), - 0 + 0, ) === n ); } diff --git a/assign-cookies/index.ts b/assign-cookies/index.ts index 1914c287..a80fc19f 100644 --- a/assign-cookies/index.ts +++ b/assign-cookies/index.ts @@ -1,14 +1,14 @@ function findContentChildren(g: number[], s: number[]): number { - g = g.sort((a, b) => a - b) - s = s.sort((a, b) => a - b) - let result = 0 - let index = s.length - 1 - for(let i = g.length - 1; i >= 0; i--) { - if(index >= 0 && s[index] >= g[i]) { - result++ - index-- + g = g.sort((a, b) => a - b); + s = s.sort((a, b) => a - b); + let result = 0; + let index = s.length - 1; + for (let i = g.length - 1; i >= 0; i--) { + if (index >= 0 && s[index] >= g[i]) { + result++; + index--; } - } - return result + } + return result; } -export default findContentChildren +export default findContentChildren; diff --git a/average-of-levels-in-binary-tree/index.ts b/average-of-levels-in-binary-tree/index.ts index 9c950b1c..c2f37ed2 100644 --- a/average-of-levels-in-binary-tree/index.ts +++ b/average-of-levels-in-binary-tree/index.ts @@ -21,6 +21,6 @@ function level(nodes: TreeNode[], output: (r: number) => void) { nodes .map((n) => [n.left, n.right].filter(Boolean) as TreeNode[]) .flat(), - output + output, ); } diff --git a/basic-calculator-iv/index.ts b/basic-calculator-iv/index.ts index b0e61ede..32bfb474 100644 --- a/basic-calculator-iv/index.ts +++ b/basic-calculator-iv/index.ts @@ -4,7 +4,7 @@ import { tokenize } from "./tokenize.ts"; export default function basicCalculatorIV( expression: string, evalvars: string[], - evalints: number[] + evalints: number[], ): string[] { const tokens = tokenize(expression, evalvars, evalints); return parse(tokens).toList(); diff --git a/beautiful-arrangement/index.ts b/beautiful-arrangement/index.ts index a7d9a082..deb3c957 100644 --- a/beautiful-arrangement/index.ts +++ b/beautiful-arrangement/index.ts @@ -2,5 +2,20 @@ export default function countArrangement(n: number): number { return cache[n] ?? 0; } const cache = [ - 0, 1, 2, 3, 8, 10, 36, 41, 132, 250, 700, 750, 4010, 4237, 10680, 24679, + 0, + 1, + 2, + 3, + 8, + 10, + 36, + 41, + 132, + 250, + 700, + 750, + 4010, + 4237, + 10680, + 24679, ]; diff --git a/best-time-to-buy-and-sell-stock-iv/index.ts b/best-time-to-buy-and-sell-stock-iv/index.ts index 3f1c6aa9..e7eb00bf 100644 --- a/best-time-to-buy-and-sell-stock-iv/index.ts +++ b/best-time-to-buy-and-sell-stock-iv/index.ts @@ -3,8 +3,9 @@ function maxProfit(k: number, prices: number[]): number { return 0; } - const dp: number[][] = Array.from(Array(prices.length), () => - Array(2 * k + 1).fill(0) + const dp: number[][] = Array.from( + Array(prices.length), + () => Array(2 * k + 1).fill(0), ); for (let j = 1; j < 2 * k; j += 2) { @@ -16,7 +17,7 @@ function maxProfit(k: number, prices: number[]): number { dp[i][j + 1] = Math.max(dp[i - 1][j + 1], dp[i - 1][j] - prices[i]); dp[i][j + 2] = Math.max( dp[i - 1][j + 2], - dp[i - 1][j + 1] + prices[i] + dp[i - 1][j + 1] + prices[i], ); } } diff --git a/binary-tree-upside-down/index.ts b/binary-tree-upside-down/index.ts index c4478aed..c9a363f1 100644 --- a/binary-tree-upside-down/index.ts +++ b/binary-tree-upside-down/index.ts @@ -1,7 +1,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function upsideDownBinaryTree( - root: TreeNode | null + root: TreeNode | null, ): TreeNode | null { if (root == null) { return root; diff --git a/boats-to-save-people/index.ts b/boats-to-save-people/index.ts index 2a483c70..a50a1071 100644 --- a/boats-to-save-people/index.ts +++ b/boats-to-save-people/index.ts @@ -1,6 +1,6 @@ export default function numRescueBoats( people: number[], - limit: number + limit: number, ): number { let l = 0, r = people.length - 1; diff --git a/booking-concert-tickets-in-groups/index.ts b/booking-concert-tickets-in-groups/index.ts index 4defaea2..9ef774de 100644 --- a/booking-concert-tickets-in-groups/index.ts +++ b/booking-concert-tickets-in-groups/index.ts @@ -11,13 +11,13 @@ export default class BookMyShow { 0, n - 1, () => m, - (a, b) => Math.max(a, b) + (a, b) => Math.max(a, b), ); this.#sumSegTree = new SegmentTree( 0, n - 1, () => m, - (a, b) => a + b + (a, b) => a + b, ); } diff --git a/boolean-evaluation-lcci/index.ts b/boolean-evaluation-lcci/index.ts index 3af8dbe6..a5298415 100644 --- a/boolean-evaluation-lcci/index.ts +++ b/boolean-evaluation-lcci/index.ts @@ -22,13 +22,13 @@ function countEval(s: string, result: number): number { const right0 = dp[j + 1][i + step][0], right1 = dp[j + 1][i + step][1]; if (s[j] == "&") { - dp[i][i + step][0] += - left0 * (right0 + right1) + left1 * right0; + dp[i][i + step][0] += left0 * (right0 + right1) + + left1 * right0; dp[i][i + step][1] += left1 * right1; } else if (s[j] == "|") { dp[i][i + step][0] += left0 * right0; - dp[i][i + step][1] += - left0 * right1 + left1 * (right0 + right1); + dp[i][i + step][1] += left0 * right1 + + left1 * (right0 + right1); } else { //s[j]=='^' dp[i][i + step][0] += left0 * right0 + left1 * right1; diff --git a/break-a-palindrome/index.ts b/break-a-palindrome/index.ts index b28974ee..c0abf320 100644 --- a/break-a-palindrome/index.ts +++ b/break-a-palindrome/index.ts @@ -3,7 +3,7 @@ export default function breakPalindrome(palindrome: string): string { const str = [...palindrome]; const index = str.findIndex( - (c, i) => c !== "a" && i < Math.floor(palindrome.length / 2) + (c, i) => c !== "a" && i < Math.floor(palindrome.length / 2), ); if (index < 0) return str.slice(0, str.length - 1).join("") + "b"; return str.map((v, i) => (i === index ? "a" : v)).join(""); diff --git a/bulls-and-cows/index.ts b/bulls-and-cows/index.ts index 89a4c425..714178c0 100644 --- a/bulls-and-cows/index.ts +++ b/bulls-and-cows/index.ts @@ -5,11 +5,10 @@ function getHint(secret: string, guess: string): string { const cntS = counter(secret); const cntG = counter(guess); - const cows = - [...cntS.entries()].reduce( - (p, [k, v]) => p + Math.min(v, cntG.get(k) ?? 0), - 0 - ) - bulls; + const cows = [...cntS.entries()].reduce( + (p, [k, v]) => p + Math.min(v, cntG.get(k) ?? 0), + 0, + ) - bulls; return `${bulls}A${cows}B`; } export default getHint; diff --git a/calculate-amount-paid-in-taxes/index.ts b/calculate-amount-paid-in-taxes/index.ts index 9d3cc5cc..a44a280e 100644 --- a/calculate-amount-paid-in-taxes/index.ts +++ b/calculate-amount-paid-in-taxes/index.ts @@ -7,8 +7,7 @@ function calculateTax(brackets: number[][], income: number): number { if (brackets[i][1] === 0) a += 0; else a += brackets[i][0] * (brackets[i][1] / 100); } else { - a += - (brackets[i][0] - brackets[i - 1][0]) * + a += (brackets[i][0] - brackets[i - 1][0]) * (brackets[i][1] / 100); } } else { diff --git a/car-fleet/index.ts b/car-fleet/index.ts index e0dcd65e..3a8fc04c 100644 --- a/car-fleet/index.ts +++ b/car-fleet/index.ts @@ -1,7 +1,7 @@ export default function carFleet( target: number, position: number[], - speed: number[] + speed: number[], ): number { const n = position.length; const cars = position.map((v, i) => [v, (target - v) / speed[i]]); diff --git a/champagne-tower/index.ts b/champagne-tower/index.ts index b242ffb1..03123305 100644 --- a/champagne-tower/index.ts +++ b/champagne-tower/index.ts @@ -1,7 +1,7 @@ export default function champagneTower( poured: number, query_row: number, - query_glass: number + query_glass: number, ): number { let row = [poured]; for (let i = 1; i <= query_row; i++) { diff --git a/change-minimum-characters-to-satisfy-one-of-three-conditions/index.ts b/change-minimum-characters-to-satisfy-one-of-three-conditions/index.ts index 5f67b5eb..c12c35f3 100644 --- a/change-minimum-characters-to-satisfy-one-of-three-conditions/index.ts +++ b/change-minimum-characters-to-satisfy-one-of-three-conditions/index.ts @@ -11,12 +11,12 @@ export default function minCharacters(a: string, b: string): number { ans = Math.min( ans, fA.slice(0, i).reduce((a, b) => a + b, 0) + - fB.slice(i).reduce((a, b) => a + b, 0) + fB.slice(i).reduce((a, b) => a + b, 0), ); ans = Math.min( ans, fB.slice(0, i).reduce((a, b) => a + b, 0) + - fA.slice(i).reduce((a, b) => a + b, 0) + fA.slice(i).reduce((a, b) => a + b, 0), ); } return ans; diff --git a/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.ts b/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.ts index d1a6f6c4..8b6b8562 100644 --- a/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.ts +++ b/check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.ts @@ -1,6 +1,6 @@ export default function isPrefixOfWord( sentence: string, - searchWord: string + searchWord: string, ): number { const index = sentence .split(" ") diff --git a/check-if-number-has-equal-digit-count-and-digit-value/index.ts b/check-if-number-has-equal-digit-count-and-digit-value/index.ts index 2d884855..358ec877 100644 --- a/check-if-number-has-equal-digit-count-and-digit-value/index.ts +++ b/check-if-number-has-equal-digit-count-and-digit-value/index.ts @@ -1,7 +1,7 @@ function digitCount(num: string): boolean { const cnt: number[] = [...num].reduce( (p: number[], v: string) => (p[Number(v)]++, p), - Array(10).fill(0) + Array(10).fill(0), ); return num === cnt.slice(0, num.length).join(""); diff --git a/check-if-two-string-arrays-are-equivalent/index.ts b/check-if-two-string-arrays-are-equivalent/index.ts index 97d8e8bf..a5d19045 100644 --- a/check-if-two-string-arrays-are-equivalent/index.ts +++ b/check-if-two-string-arrays-are-equivalent/index.ts @@ -1,6 +1,6 @@ export default function arrayStringsAreEqual( word1: string[], - word2: string[] + word2: string[], ): boolean { return word1.join("") === word2.join(""); } diff --git a/checking-existence-of-edge-length-limited-paths-ii/index.ts b/checking-existence-of-edge-length-limited-paths-ii/index.ts index 550cdf4a..38ecfcfd 100644 --- a/checking-existence-of-edge-length-limited-paths-ii/index.ts +++ b/checking-existence-of-edge-length-limited-paths-ii/index.ts @@ -42,12 +42,11 @@ export default class DistanceLimitedPathsExist { return this.#findSnapRoot(p, limit) === this.#findSnapRoot(q, limit); } #findSnapRoot(node: number, limit: number): number { - const index = - lowerBound( - 0, - this.#snaps[node].length, - (i: number) => this.#snaps[node][i][0] - limit - ) - 1; + const index = lowerBound( + 0, + this.#snaps[node].length, + (i: number) => this.#snaps[node][i][0] - limit, + ) - 1; const f = this.#snaps[node][index][1]; if (f == node) return f; diff --git a/checking-existence-of-edge-length-limited-paths/index.ts b/checking-existence-of-edge-length-limited-paths/index.ts index 003c079f..13211b76 100644 --- a/checking-existence-of-edge-length-limited-paths/index.ts +++ b/checking-existence-of-edge-length-limited-paths/index.ts @@ -3,7 +3,7 @@ import { UnionFind } from "../largest-component-size-by-common-factor/UnionFind. function distanceLimitedPathsExist( _n: number, edgeList: number[][], - queries: number[][] + queries: number[][], ): boolean[] { const uf = new UnionFind(); diff --git a/chou-shu-lcof/index.ts b/chou-shu-lcof/index.ts index 36697bc1..a62795e5 100644 --- a/chou-shu-lcof/index.ts +++ b/chou-shu-lcof/index.ts @@ -2,221 +2,1696 @@ function nthUglyNumber(n: number): number { return cache[n - 1] ?? 1; } const cache = [ - 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36, 40, - 45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 96, 100, 108, 120, 125, 128, - 135, 144, 150, 160, 162, 180, 192, 200, 216, 225, 240, 243, 250, 256, 270, - 288, 300, 320, 324, 360, 375, 384, 400, 405, 432, 450, 480, 486, 500, 512, - 540, 576, 600, 625, 640, 648, 675, 720, 729, 750, 768, 800, 810, 864, 900, - 960, 972, 1000, 1024, 1080, 1125, 1152, 1200, 1215, 1250, 1280, 1296, 1350, - 1440, 1458, 1500, 1536, 1600, 1620, 1728, 1800, 1875, 1920, 1944, 2000, - 2025, 2048, 2160, 2187, 2250, 2304, 2400, 2430, 2500, 2560, 2592, 2700, - 2880, 2916, 3000, 3072, 3125, 3200, 3240, 3375, 3456, 3600, 3645, 3750, - 3840, 3888, 4000, 4050, 4096, 4320, 4374, 4500, 4608, 4800, 4860, 5000, - 5120, 5184, 5400, 5625, 5760, 5832, 6000, 6075, 6144, 6250, 6400, 6480, - 6561, 6750, 6912, 7200, 7290, 7500, 7680, 7776, 8000, 8100, 8192, 8640, - 8748, 9000, 9216, 9375, 9600, 9720, 10000, 10125, 10240, 10368, 10800, - 10935, 11250, 11520, 11664, 12000, 12150, 12288, 12500, 12800, 12960, 13122, - 13500, 13824, 14400, 14580, 15000, 15360, 15552, 15625, 16000, 16200, 16384, - 16875, 17280, 17496, 18000, 18225, 18432, 18750, 19200, 19440, 19683, 20000, - 20250, 20480, 20736, 21600, 21870, 22500, 23040, 23328, 24000, 24300, 24576, - 25000, 25600, 25920, 26244, 27000, 27648, 28125, 28800, 29160, 30000, 30375, - 30720, 31104, 31250, 32000, 32400, 32768, 32805, 33750, 34560, 34992, 36000, - 36450, 36864, 37500, 38400, 38880, 39366, 40000, 40500, 40960, 41472, 43200, - 43740, 45000, 46080, 46656, 46875, 48000, 48600, 49152, 50000, 50625, 51200, - 51840, 52488, 54000, 54675, 55296, 56250, 57600, 58320, 59049, 60000, 60750, - 61440, 62208, 62500, 64000, 64800, 65536, 65610, 67500, 69120, 69984, 72000, - 72900, 73728, 75000, 76800, 77760, 78125, 78732, 80000, 81000, 81920, 82944, - 84375, 86400, 87480, 90000, 91125, 92160, 93312, 93750, 96000, 97200, 98304, - 98415, 100000, 101250, 102400, 103680, 104976, 108000, 109350, 110592, - 112500, 115200, 116640, 118098, 120000, 121500, 122880, 124416, 125000, - 128000, 129600, 131072, 131220, 135000, 138240, 139968, 140625, 144000, - 145800, 147456, 150000, 151875, 153600, 155520, 156250, 157464, 160000, - 162000, 163840, 164025, 165888, 168750, 172800, 174960, 177147, 180000, - 182250, 184320, 186624, 187500, 192000, 194400, 196608, 196830, 200000, - 202500, 204800, 207360, 209952, 216000, 218700, 221184, 225000, 230400, - 233280, 234375, 236196, 240000, 243000, 245760, 248832, 250000, 253125, - 256000, 259200, 262144, 262440, 270000, 273375, 276480, 279936, 281250, - 288000, 291600, 294912, 295245, 300000, 303750, 307200, 311040, 312500, - 314928, 320000, 324000, 327680, 328050, 331776, 337500, 345600, 349920, - 354294, 360000, 364500, 368640, 373248, 375000, 384000, 388800, 390625, - 393216, 393660, 400000, 405000, 409600, 414720, 419904, 421875, 432000, - 437400, 442368, 450000, 455625, 460800, 466560, 468750, 472392, 480000, - 486000, 491520, 492075, 497664, 500000, 506250, 512000, 518400, 524288, - 524880, 531441, 540000, 546750, 552960, 559872, 562500, 576000, 583200, - 589824, 590490, 600000, 607500, 614400, 622080, 625000, 629856, 640000, - 648000, 655360, 656100, 663552, 675000, 691200, 699840, 703125, 708588, - 720000, 729000, 737280, 746496, 750000, 759375, 768000, 777600, 781250, - 786432, 787320, 800000, 810000, 819200, 820125, 829440, 839808, 843750, - 864000, 874800, 884736, 885735, 900000, 911250, 921600, 933120, 937500, - 944784, 960000, 972000, 983040, 984150, 995328, 1000000, 1012500, 1024000, - 1036800, 1048576, 1049760, 1062882, 1080000, 1093500, 1105920, 1119744, - 1125000, 1152000, 1166400, 1171875, 1179648, 1180980, 1200000, 1215000, - 1228800, 1244160, 1250000, 1259712, 1265625, 1280000, 1296000, 1310720, - 1312200, 1327104, 1350000, 1366875, 1382400, 1399680, 1406250, 1417176, - 1440000, 1458000, 1474560, 1476225, 1492992, 1500000, 1518750, 1536000, - 1555200, 1562500, 1572864, 1574640, 1594323, 1600000, 1620000, 1638400, - 1640250, 1658880, 1679616, 1687500, 1728000, 1749600, 1769472, 1771470, - 1800000, 1822500, 1843200, 1866240, 1875000, 1889568, 1920000, 1944000, - 1953125, 1966080, 1968300, 1990656, 2000000, 2025000, 2048000, 2073600, - 2097152, 2099520, 2109375, 2125764, 2160000, 2187000, 2211840, 2239488, - 2250000, 2278125, 2304000, 2332800, 2343750, 2359296, 2361960, 2400000, - 2430000, 2457600, 2460375, 2488320, 2500000, 2519424, 2531250, 2560000, - 2592000, 2621440, 2624400, 2654208, 2657205, 2700000, 2733750, 2764800, - 2799360, 2812500, 2834352, 2880000, 2916000, 2949120, 2952450, 2985984, - 3000000, 3037500, 3072000, 3110400, 3125000, 3145728, 3149280, 3188646, - 3200000, 3240000, 3276800, 3280500, 3317760, 3359232, 3375000, 3456000, - 3499200, 3515625, 3538944, 3542940, 3600000, 3645000, 3686400, 3732480, - 3750000, 3779136, 3796875, 3840000, 3888000, 3906250, 3932160, 3936600, - 3981312, 4000000, 4050000, 4096000, 4100625, 4147200, 4194304, 4199040, - 4218750, 4251528, 4320000, 4374000, 4423680, 4428675, 4478976, 4500000, - 4556250, 4608000, 4665600, 4687500, 4718592, 4723920, 4782969, 4800000, - 4860000, 4915200, 4920750, 4976640, 5000000, 5038848, 5062500, 5120000, - 5184000, 5242880, 5248800, 5308416, 5314410, 5400000, 5467500, 5529600, - 5598720, 5625000, 5668704, 5760000, 5832000, 5859375, 5898240, 5904900, - 5971968, 6000000, 6075000, 6144000, 6220800, 6250000, 6291456, 6298560, - 6328125, 6377292, 6400000, 6480000, 6553600, 6561000, 6635520, 6718464, - 6750000, 6834375, 6912000, 6998400, 7031250, 7077888, 7085880, 7200000, - 7290000, 7372800, 7381125, 7464960, 7500000, 7558272, 7593750, 7680000, - 7776000, 7812500, 7864320, 7873200, 7962624, 7971615, 8000000, 8100000, - 8192000, 8201250, 8294400, 8388608, 8398080, 8437500, 8503056, 8640000, - 8748000, 8847360, 8857350, 8957952, 9000000, 9112500, 9216000, 9331200, - 9375000, 9437184, 9447840, 9565938, 9600000, 9720000, 9765625, 9830400, - 9841500, 9953280, 10000000, 10077696, 10125000, 10240000, 10368000, - 10485760, 10497600, 10546875, 10616832, 10628820, 10800000, 10935000, - 11059200, 11197440, 11250000, 11337408, 11390625, 11520000, 11664000, - 11718750, 11796480, 11809800, 11943936, 12000000, 12150000, 12288000, - 12301875, 12441600, 12500000, 12582912, 12597120, 12656250, 12754584, - 12800000, 12960000, 13107200, 13122000, 13271040, 13286025, 13436928, - 13500000, 13668750, 13824000, 13996800, 14062500, 14155776, 14171760, - 14348907, 14400000, 14580000, 14745600, 14762250, 14929920, 15000000, - 15116544, 15187500, 15360000, 15552000, 15625000, 15728640, 15746400, - 15925248, 15943230, 16000000, 16200000, 16384000, 16402500, 16588800, - 16777216, 16796160, 16875000, 17006112, 17280000, 17496000, 17578125, - 17694720, 17714700, 17915904, 18000000, 18225000, 18432000, 18662400, - 18750000, 18874368, 18895680, 18984375, 19131876, 19200000, 19440000, - 19531250, 19660800, 19683000, 19906560, 20000000, 20155392, 20250000, - 20480000, 20503125, 20736000, 20971520, 20995200, 21093750, 21233664, - 21257640, 21600000, 21870000, 22118400, 22143375, 22394880, 22500000, - 22674816, 22781250, 23040000, 23328000, 23437500, 23592960, 23619600, - 23887872, 23914845, 24000000, 24300000, 24576000, 24603750, 24883200, - 25000000, 25165824, 25194240, 25312500, 25509168, 25600000, 25920000, - 26214400, 26244000, 26542080, 26572050, 26873856, 27000000, 27337500, - 27648000, 27993600, 28125000, 28311552, 28343520, 28697814, 28800000, - 29160000, 29296875, 29491200, 29524500, 29859840, 30000000, 30233088, - 30375000, 30720000, 31104000, 31250000, 31457280, 31492800, 31640625, - 31850496, 31886460, 32000000, 32400000, 32768000, 32805000, 33177600, - 33554432, 33592320, 33750000, 34012224, 34171875, 34560000, 34992000, - 35156250, 35389440, 35429400, 35831808, 36000000, 36450000, 36864000, - 36905625, 37324800, 37500000, 37748736, 37791360, 37968750, 38263752, - 38400000, 38880000, 39062500, 39321600, 39366000, 39813120, 39858075, - 40000000, 40310784, 40500000, 40960000, 41006250, 41472000, 41943040, - 41990400, 42187500, 42467328, 42515280, 43046721, 43200000, 43740000, - 44236800, 44286750, 44789760, 45000000, 45349632, 45562500, 46080000, - 46656000, 46875000, 47185920, 47239200, 47775744, 47829690, 48000000, - 48600000, 48828125, 49152000, 49207500, 49766400, 50000000, 50331648, - 50388480, 50625000, 51018336, 51200000, 51840000, 52428800, 52488000, - 52734375, 53084160, 53144100, 53747712, 54000000, 54675000, 55296000, - 55987200, 56250000, 56623104, 56687040, 56953125, 57395628, 57600000, - 58320000, 58593750, 58982400, 59049000, 59719680, 60000000, 60466176, - 60750000, 61440000, 61509375, 62208000, 62500000, 62914560, 62985600, - 63281250, 63700992, 63772920, 64000000, 64800000, 65536000, 65610000, - 66355200, 66430125, 67108864, 67184640, 67500000, 68024448, 68343750, - 69120000, 69984000, 70312500, 70778880, 70858800, 71663616, 71744535, - 72000000, 72900000, 73728000, 73811250, 74649600, 75000000, 75497472, - 75582720, 75937500, 76527504, 76800000, 77760000, 78125000, 78643200, - 78732000, 79626240, 79716150, 80000000, 80621568, 81000000, 81920000, - 82012500, 82944000, 83886080, 83980800, 84375000, 84934656, 85030560, - 86093442, 86400000, 87480000, 87890625, 88473600, 88573500, 89579520, - 90000000, 90699264, 91125000, 92160000, 93312000, 93750000, 94371840, - 94478400, 94921875, 95551488, 95659380, 96000000, 97200000, 97656250, - 98304000, 98415000, 99532800, 100000000, 100663296, 100776960, 101250000, - 102036672, 102400000, 102515625, 103680000, 104857600, 104976000, 105468750, - 106168320, 106288200, 107495424, 108000000, 109350000, 110592000, 110716875, - 111974400, 112500000, 113246208, 113374080, 113906250, 114791256, 115200000, - 116640000, 117187500, 117964800, 118098000, 119439360, 119574225, 120000000, - 120932352, 121500000, 122880000, 123018750, 124416000, 125000000, 125829120, - 125971200, 126562500, 127401984, 127545840, 128000000, 129140163, 129600000, - 131072000, 131220000, 132710400, 132860250, 134217728, 134369280, 135000000, - 136048896, 136687500, 138240000, 139968000, 140625000, 141557760, 141717600, - 143327232, 143489070, 144000000, 145800000, 146484375, 147456000, 147622500, - 149299200, 150000000, 150994944, 151165440, 151875000, 153055008, 153600000, - 155520000, 156250000, 157286400, 157464000, 158203125, 159252480, 159432300, - 160000000, 161243136, 162000000, 163840000, 164025000, 165888000, 167772160, - 167961600, 168750000, 169869312, 170061120, 170859375, 172186884, 172800000, - 174960000, 175781250, 176947200, 177147000, 179159040, 180000000, 181398528, - 182250000, 184320000, 184528125, 186624000, 187500000, 188743680, 188956800, - 189843750, 191102976, 191318760, 192000000, 194400000, 195312500, 196608000, - 196830000, 199065600, 199290375, 200000000, 201326592, 201553920, 202500000, - 204073344, 204800000, 205031250, 207360000, 209715200, 209952000, 210937500, - 212336640, 212576400, 214990848, 215233605, 216000000, 218700000, 221184000, - 221433750, 223948800, 225000000, 226492416, 226748160, 227812500, 229582512, - 230400000, 233280000, 234375000, 235929600, 236196000, 238878720, 239148450, - 240000000, 241864704, 243000000, 244140625, 245760000, 246037500, 248832000, - 250000000, 251658240, 251942400, 253125000, 254803968, 255091680, 256000000, - 258280326, 259200000, 262144000, 262440000, 263671875, 265420800, 265720500, - 268435456, 268738560, 270000000, 272097792, 273375000, 276480000, 279936000, - 281250000, 283115520, 283435200, 284765625, 286654464, 286978140, 288000000, - 291600000, 292968750, 294912000, 295245000, 298598400, 300000000, 301989888, - 302330880, 303750000, 306110016, 307200000, 307546875, 311040000, 312500000, - 314572800, 314928000, 316406250, 318504960, 318864600, 320000000, 322486272, - 324000000, 327680000, 328050000, 331776000, 332150625, 335544320, 335923200, - 337500000, 339738624, 340122240, 341718750, 344373768, 345600000, 349920000, - 351562500, 353894400, 354294000, 358318080, 358722675, 360000000, 362797056, - 364500000, 368640000, 369056250, 373248000, 375000000, 377487360, 377913600, - 379687500, 382205952, 382637520, 384000000, 387420489, 388800000, 390625000, - 393216000, 393660000, 398131200, 398580750, 400000000, 402653184, 403107840, - 405000000, 408146688, 409600000, 410062500, 414720000, 419430400, 419904000, - 421875000, 424673280, 425152800, 429981696, 430467210, 432000000, 437400000, - 439453125, 442368000, 442867500, 447897600, 450000000, 452984832, 453496320, - 455625000, 459165024, 460800000, 466560000, 468750000, 471859200, 472392000, - 474609375, 477757440, 478296900, 480000000, 483729408, 486000000, 488281250, - 491520000, 492075000, 497664000, 500000000, 503316480, 503884800, 506250000, - 509607936, 510183360, 512000000, 512578125, 516560652, 518400000, 524288000, - 524880000, 527343750, 530841600, 531441000, 536870912, 537477120, 540000000, - 544195584, 546750000, 552960000, 553584375, 559872000, 562500000, 566231040, - 566870400, 569531250, 573308928, 573956280, 576000000, 583200000, 585937500, - 589824000, 590490000, 597196800, 597871125, 600000000, 603979776, 604661760, - 607500000, 612220032, 614400000, 615093750, 622080000, 625000000, 629145600, - 629856000, 632812500, 637009920, 637729200, 640000000, 644972544, 645700815, - 648000000, 655360000, 656100000, 663552000, 664301250, 671088640, 671846400, - 675000000, 679477248, 680244480, 683437500, 688747536, 691200000, 699840000, - 703125000, 707788800, 708588000, 716636160, 717445350, 720000000, 725594112, - 729000000, 732421875, 737280000, 738112500, 746496000, 750000000, 754974720, - 755827200, 759375000, 764411904, 765275040, 768000000, 774840978, 777600000, - 781250000, 786432000, 787320000, 791015625, 796262400, 797161500, 800000000, - 805306368, 806215680, 810000000, 816293376, 819200000, 820125000, 829440000, - 838860800, 839808000, 843750000, 849346560, 850305600, 854296875, 859963392, - 860934420, 864000000, 874800000, 878906250, 884736000, 885735000, 895795200, - 900000000, 905969664, 906992640, 911250000, 918330048, 921600000, 922640625, - 933120000, 937500000, 943718400, 944784000, 949218750, 955514880, 956593800, - 960000000, 967458816, 972000000, 976562500, 983040000, 984150000, 995328000, - 996451875, 1000000000, 1006632960, 1007769600, 1012500000, 1019215872, - 1020366720, 1024000000, 1025156250, 1033121304, 1036800000, 1048576000, - 1049760000, 1054687500, 1061683200, 1062882000, 1073741824, 1074954240, - 1076168025, 1080000000, 1088391168, 1093500000, 1105920000, 1107168750, - 1119744000, 1125000000, 1132462080, 1133740800, 1139062500, 1146617856, - 1147912560, 1152000000, 1162261467, 1166400000, 1171875000, 1179648000, - 1180980000, 1194393600, 1195742250, 1200000000, 1207959552, 1209323520, - 1215000000, 1220703125, 1224440064, 1228800000, 1230187500, 1244160000, - 1250000000, 1258291200, 1259712000, 1265625000, 1274019840, 1275458400, - 1280000000, 1289945088, 1291401630, 1296000000, 1310720000, 1312200000, - 1318359375, 1327104000, 1328602500, 1342177280, 1343692800, 1350000000, - 1358954496, 1360488960, 1366875000, 1377495072, 1382400000, 1399680000, - 1406250000, 1415577600, 1417176000, 1423828125, 1433272320, 1434890700, - 1440000000, 1451188224, 1458000000, 1464843750, 1474560000, 1476225000, - 1492992000, 1500000000, 1509949440, 1511654400, 1518750000, 1528823808, - 1530550080, 1536000000, 1537734375, 1549681956, 1555200000, 1562500000, - 1572864000, 1574640000, 1582031250, 1592524800, 1594323000, 1600000000, - 1610612736, 1612431360, 1620000000, 1632586752, 1638400000, 1640250000, - 1658880000, 1660753125, 1677721600, 1679616000, 1687500000, 1698693120, - 1700611200, 1708593750, 1719926784, 1721868840, 1728000000, 1749600000, - 1757812500, 1769472000, 1771470000, 1791590400, 1793613375, 1800000000, - 1811939328, 1813985280, 1822500000, 1836660096, 1843200000, 1845281250, - 1866240000, 1875000000, 1887436800, 1889568000, 1898437500, 1911029760, - 1913187600, 1920000000, 1934917632, 1937102445, 1944000000, 1953125000, - 1966080000, 1968300000, 1990656000, 1992903750, 2000000000, 2013265920, - 2015539200, 2025000000, 2038431744, 2040733440, 2048000000, 2050312500, - 2066242608, 2073600000, 2097152000, 2099520000, 2109375000, 2123366400, + 1, + 2, + 3, + 4, + 5, + 6, + 8, + 9, + 10, + 12, + 15, + 16, + 18, + 20, + 24, + 25, + 27, + 30, + 32, + 36, + 40, + 45, + 48, + 50, + 54, + 60, + 64, + 72, + 75, + 80, + 81, + 90, + 96, + 100, + 108, + 120, + 125, + 128, + 135, + 144, + 150, + 160, + 162, + 180, + 192, + 200, + 216, + 225, + 240, + 243, + 250, + 256, + 270, + 288, + 300, + 320, + 324, + 360, + 375, + 384, + 400, + 405, + 432, + 450, + 480, + 486, + 500, + 512, + 540, + 576, + 600, + 625, + 640, + 648, + 675, + 720, + 729, + 750, + 768, + 800, + 810, + 864, + 900, + 960, + 972, + 1000, + 1024, + 1080, + 1125, + 1152, + 1200, + 1215, + 1250, + 1280, + 1296, + 1350, + 1440, + 1458, + 1500, + 1536, + 1600, + 1620, + 1728, + 1800, + 1875, + 1920, + 1944, + 2000, + 2025, + 2048, + 2160, + 2187, + 2250, + 2304, + 2400, + 2430, + 2500, + 2560, + 2592, + 2700, + 2880, + 2916, + 3000, + 3072, + 3125, + 3200, + 3240, + 3375, + 3456, + 3600, + 3645, + 3750, + 3840, + 3888, + 4000, + 4050, + 4096, + 4320, + 4374, + 4500, + 4608, + 4800, + 4860, + 5000, + 5120, + 5184, + 5400, + 5625, + 5760, + 5832, + 6000, + 6075, + 6144, + 6250, + 6400, + 6480, + 6561, + 6750, + 6912, + 7200, + 7290, + 7500, + 7680, + 7776, + 8000, + 8100, + 8192, + 8640, + 8748, + 9000, + 9216, + 9375, + 9600, + 9720, + 10000, + 10125, + 10240, + 10368, + 10800, + 10935, + 11250, + 11520, + 11664, + 12000, + 12150, + 12288, + 12500, + 12800, + 12960, + 13122, + 13500, + 13824, + 14400, + 14580, + 15000, + 15360, + 15552, + 15625, + 16000, + 16200, + 16384, + 16875, + 17280, + 17496, + 18000, + 18225, + 18432, + 18750, + 19200, + 19440, + 19683, + 20000, + 20250, + 20480, + 20736, + 21600, + 21870, + 22500, + 23040, + 23328, + 24000, + 24300, + 24576, + 25000, + 25600, + 25920, + 26244, + 27000, + 27648, + 28125, + 28800, + 29160, + 30000, + 30375, + 30720, + 31104, + 31250, + 32000, + 32400, + 32768, + 32805, + 33750, + 34560, + 34992, + 36000, + 36450, + 36864, + 37500, + 38400, + 38880, + 39366, + 40000, + 40500, + 40960, + 41472, + 43200, + 43740, + 45000, + 46080, + 46656, + 46875, + 48000, + 48600, + 49152, + 50000, + 50625, + 51200, + 51840, + 52488, + 54000, + 54675, + 55296, + 56250, + 57600, + 58320, + 59049, + 60000, + 60750, + 61440, + 62208, + 62500, + 64000, + 64800, + 65536, + 65610, + 67500, + 69120, + 69984, + 72000, + 72900, + 73728, + 75000, + 76800, + 77760, + 78125, + 78732, + 80000, + 81000, + 81920, + 82944, + 84375, + 86400, + 87480, + 90000, + 91125, + 92160, + 93312, + 93750, + 96000, + 97200, + 98304, + 98415, + 100000, + 101250, + 102400, + 103680, + 104976, + 108000, + 109350, + 110592, + 112500, + 115200, + 116640, + 118098, + 120000, + 121500, + 122880, + 124416, + 125000, + 128000, + 129600, + 131072, + 131220, + 135000, + 138240, + 139968, + 140625, + 144000, + 145800, + 147456, + 150000, + 151875, + 153600, + 155520, + 156250, + 157464, + 160000, + 162000, + 163840, + 164025, + 165888, + 168750, + 172800, + 174960, + 177147, + 180000, + 182250, + 184320, + 186624, + 187500, + 192000, + 194400, + 196608, + 196830, + 200000, + 202500, + 204800, + 207360, + 209952, + 216000, + 218700, + 221184, + 225000, + 230400, + 233280, + 234375, + 236196, + 240000, + 243000, + 245760, + 248832, + 250000, + 253125, + 256000, + 259200, + 262144, + 262440, + 270000, + 273375, + 276480, + 279936, + 281250, + 288000, + 291600, + 294912, + 295245, + 300000, + 303750, + 307200, + 311040, + 312500, + 314928, + 320000, + 324000, + 327680, + 328050, + 331776, + 337500, + 345600, + 349920, + 354294, + 360000, + 364500, + 368640, + 373248, + 375000, + 384000, + 388800, + 390625, + 393216, + 393660, + 400000, + 405000, + 409600, + 414720, + 419904, + 421875, + 432000, + 437400, + 442368, + 450000, + 455625, + 460800, + 466560, + 468750, + 472392, + 480000, + 486000, + 491520, + 492075, + 497664, + 500000, + 506250, + 512000, + 518400, + 524288, + 524880, + 531441, + 540000, + 546750, + 552960, + 559872, + 562500, + 576000, + 583200, + 589824, + 590490, + 600000, + 607500, + 614400, + 622080, + 625000, + 629856, + 640000, + 648000, + 655360, + 656100, + 663552, + 675000, + 691200, + 699840, + 703125, + 708588, + 720000, + 729000, + 737280, + 746496, + 750000, + 759375, + 768000, + 777600, + 781250, + 786432, + 787320, + 800000, + 810000, + 819200, + 820125, + 829440, + 839808, + 843750, + 864000, + 874800, + 884736, + 885735, + 900000, + 911250, + 921600, + 933120, + 937500, + 944784, + 960000, + 972000, + 983040, + 984150, + 995328, + 1000000, + 1012500, + 1024000, + 1036800, + 1048576, + 1049760, + 1062882, + 1080000, + 1093500, + 1105920, + 1119744, + 1125000, + 1152000, + 1166400, + 1171875, + 1179648, + 1180980, + 1200000, + 1215000, + 1228800, + 1244160, + 1250000, + 1259712, + 1265625, + 1280000, + 1296000, + 1310720, + 1312200, + 1327104, + 1350000, + 1366875, + 1382400, + 1399680, + 1406250, + 1417176, + 1440000, + 1458000, + 1474560, + 1476225, + 1492992, + 1500000, + 1518750, + 1536000, + 1555200, + 1562500, + 1572864, + 1574640, + 1594323, + 1600000, + 1620000, + 1638400, + 1640250, + 1658880, + 1679616, + 1687500, + 1728000, + 1749600, + 1769472, + 1771470, + 1800000, + 1822500, + 1843200, + 1866240, + 1875000, + 1889568, + 1920000, + 1944000, + 1953125, + 1966080, + 1968300, + 1990656, + 2000000, + 2025000, + 2048000, + 2073600, + 2097152, + 2099520, + 2109375, + 2125764, + 2160000, + 2187000, + 2211840, + 2239488, + 2250000, + 2278125, + 2304000, + 2332800, + 2343750, + 2359296, + 2361960, + 2400000, + 2430000, + 2457600, + 2460375, + 2488320, + 2500000, + 2519424, + 2531250, + 2560000, + 2592000, + 2621440, + 2624400, + 2654208, + 2657205, + 2700000, + 2733750, + 2764800, + 2799360, + 2812500, + 2834352, + 2880000, + 2916000, + 2949120, + 2952450, + 2985984, + 3000000, + 3037500, + 3072000, + 3110400, + 3125000, + 3145728, + 3149280, + 3188646, + 3200000, + 3240000, + 3276800, + 3280500, + 3317760, + 3359232, + 3375000, + 3456000, + 3499200, + 3515625, + 3538944, + 3542940, + 3600000, + 3645000, + 3686400, + 3732480, + 3750000, + 3779136, + 3796875, + 3840000, + 3888000, + 3906250, + 3932160, + 3936600, + 3981312, + 4000000, + 4050000, + 4096000, + 4100625, + 4147200, + 4194304, + 4199040, + 4218750, + 4251528, + 4320000, + 4374000, + 4423680, + 4428675, + 4478976, + 4500000, + 4556250, + 4608000, + 4665600, + 4687500, + 4718592, + 4723920, + 4782969, + 4800000, + 4860000, + 4915200, + 4920750, + 4976640, + 5000000, + 5038848, + 5062500, + 5120000, + 5184000, + 5242880, + 5248800, + 5308416, + 5314410, + 5400000, + 5467500, + 5529600, + 5598720, + 5625000, + 5668704, + 5760000, + 5832000, + 5859375, + 5898240, + 5904900, + 5971968, + 6000000, + 6075000, + 6144000, + 6220800, + 6250000, + 6291456, + 6298560, + 6328125, + 6377292, + 6400000, + 6480000, + 6553600, + 6561000, + 6635520, + 6718464, + 6750000, + 6834375, + 6912000, + 6998400, + 7031250, + 7077888, + 7085880, + 7200000, + 7290000, + 7372800, + 7381125, + 7464960, + 7500000, + 7558272, + 7593750, + 7680000, + 7776000, + 7812500, + 7864320, + 7873200, + 7962624, + 7971615, + 8000000, + 8100000, + 8192000, + 8201250, + 8294400, + 8388608, + 8398080, + 8437500, + 8503056, + 8640000, + 8748000, + 8847360, + 8857350, + 8957952, + 9000000, + 9112500, + 9216000, + 9331200, + 9375000, + 9437184, + 9447840, + 9565938, + 9600000, + 9720000, + 9765625, + 9830400, + 9841500, + 9953280, + 10000000, + 10077696, + 10125000, + 10240000, + 10368000, + 10485760, + 10497600, + 10546875, + 10616832, + 10628820, + 10800000, + 10935000, + 11059200, + 11197440, + 11250000, + 11337408, + 11390625, + 11520000, + 11664000, + 11718750, + 11796480, + 11809800, + 11943936, + 12000000, + 12150000, + 12288000, + 12301875, + 12441600, + 12500000, + 12582912, + 12597120, + 12656250, + 12754584, + 12800000, + 12960000, + 13107200, + 13122000, + 13271040, + 13286025, + 13436928, + 13500000, + 13668750, + 13824000, + 13996800, + 14062500, + 14155776, + 14171760, + 14348907, + 14400000, + 14580000, + 14745600, + 14762250, + 14929920, + 15000000, + 15116544, + 15187500, + 15360000, + 15552000, + 15625000, + 15728640, + 15746400, + 15925248, + 15943230, + 16000000, + 16200000, + 16384000, + 16402500, + 16588800, + 16777216, + 16796160, + 16875000, + 17006112, + 17280000, + 17496000, + 17578125, + 17694720, + 17714700, + 17915904, + 18000000, + 18225000, + 18432000, + 18662400, + 18750000, + 18874368, + 18895680, + 18984375, + 19131876, + 19200000, + 19440000, + 19531250, + 19660800, + 19683000, + 19906560, + 20000000, + 20155392, + 20250000, + 20480000, + 20503125, + 20736000, + 20971520, + 20995200, + 21093750, + 21233664, + 21257640, + 21600000, + 21870000, + 22118400, + 22143375, + 22394880, + 22500000, + 22674816, + 22781250, + 23040000, + 23328000, + 23437500, + 23592960, + 23619600, + 23887872, + 23914845, + 24000000, + 24300000, + 24576000, + 24603750, + 24883200, + 25000000, + 25165824, + 25194240, + 25312500, + 25509168, + 25600000, + 25920000, + 26214400, + 26244000, + 26542080, + 26572050, + 26873856, + 27000000, + 27337500, + 27648000, + 27993600, + 28125000, + 28311552, + 28343520, + 28697814, + 28800000, + 29160000, + 29296875, + 29491200, + 29524500, + 29859840, + 30000000, + 30233088, + 30375000, + 30720000, + 31104000, + 31250000, + 31457280, + 31492800, + 31640625, + 31850496, + 31886460, + 32000000, + 32400000, + 32768000, + 32805000, + 33177600, + 33554432, + 33592320, + 33750000, + 34012224, + 34171875, + 34560000, + 34992000, + 35156250, + 35389440, + 35429400, + 35831808, + 36000000, + 36450000, + 36864000, + 36905625, + 37324800, + 37500000, + 37748736, + 37791360, + 37968750, + 38263752, + 38400000, + 38880000, + 39062500, + 39321600, + 39366000, + 39813120, + 39858075, + 40000000, + 40310784, + 40500000, + 40960000, + 41006250, + 41472000, + 41943040, + 41990400, + 42187500, + 42467328, + 42515280, + 43046721, + 43200000, + 43740000, + 44236800, + 44286750, + 44789760, + 45000000, + 45349632, + 45562500, + 46080000, + 46656000, + 46875000, + 47185920, + 47239200, + 47775744, + 47829690, + 48000000, + 48600000, + 48828125, + 49152000, + 49207500, + 49766400, + 50000000, + 50331648, + 50388480, + 50625000, + 51018336, + 51200000, + 51840000, + 52428800, + 52488000, + 52734375, + 53084160, + 53144100, + 53747712, + 54000000, + 54675000, + 55296000, + 55987200, + 56250000, + 56623104, + 56687040, + 56953125, + 57395628, + 57600000, + 58320000, + 58593750, + 58982400, + 59049000, + 59719680, + 60000000, + 60466176, + 60750000, + 61440000, + 61509375, + 62208000, + 62500000, + 62914560, + 62985600, + 63281250, + 63700992, + 63772920, + 64000000, + 64800000, + 65536000, + 65610000, + 66355200, + 66430125, + 67108864, + 67184640, + 67500000, + 68024448, + 68343750, + 69120000, + 69984000, + 70312500, + 70778880, + 70858800, + 71663616, + 71744535, + 72000000, + 72900000, + 73728000, + 73811250, + 74649600, + 75000000, + 75497472, + 75582720, + 75937500, + 76527504, + 76800000, + 77760000, + 78125000, + 78643200, + 78732000, + 79626240, + 79716150, + 80000000, + 80621568, + 81000000, + 81920000, + 82012500, + 82944000, + 83886080, + 83980800, + 84375000, + 84934656, + 85030560, + 86093442, + 86400000, + 87480000, + 87890625, + 88473600, + 88573500, + 89579520, + 90000000, + 90699264, + 91125000, + 92160000, + 93312000, + 93750000, + 94371840, + 94478400, + 94921875, + 95551488, + 95659380, + 96000000, + 97200000, + 97656250, + 98304000, + 98415000, + 99532800, + 100000000, + 100663296, + 100776960, + 101250000, + 102036672, + 102400000, + 102515625, + 103680000, + 104857600, + 104976000, + 105468750, + 106168320, + 106288200, + 107495424, + 108000000, + 109350000, + 110592000, + 110716875, + 111974400, + 112500000, + 113246208, + 113374080, + 113906250, + 114791256, + 115200000, + 116640000, + 117187500, + 117964800, + 118098000, + 119439360, + 119574225, + 120000000, + 120932352, + 121500000, + 122880000, + 123018750, + 124416000, + 125000000, + 125829120, + 125971200, + 126562500, + 127401984, + 127545840, + 128000000, + 129140163, + 129600000, + 131072000, + 131220000, + 132710400, + 132860250, + 134217728, + 134369280, + 135000000, + 136048896, + 136687500, + 138240000, + 139968000, + 140625000, + 141557760, + 141717600, + 143327232, + 143489070, + 144000000, + 145800000, + 146484375, + 147456000, + 147622500, + 149299200, + 150000000, + 150994944, + 151165440, + 151875000, + 153055008, + 153600000, + 155520000, + 156250000, + 157286400, + 157464000, + 158203125, + 159252480, + 159432300, + 160000000, + 161243136, + 162000000, + 163840000, + 164025000, + 165888000, + 167772160, + 167961600, + 168750000, + 169869312, + 170061120, + 170859375, + 172186884, + 172800000, + 174960000, + 175781250, + 176947200, + 177147000, + 179159040, + 180000000, + 181398528, + 182250000, + 184320000, + 184528125, + 186624000, + 187500000, + 188743680, + 188956800, + 189843750, + 191102976, + 191318760, + 192000000, + 194400000, + 195312500, + 196608000, + 196830000, + 199065600, + 199290375, + 200000000, + 201326592, + 201553920, + 202500000, + 204073344, + 204800000, + 205031250, + 207360000, + 209715200, + 209952000, + 210937500, + 212336640, + 212576400, + 214990848, + 215233605, + 216000000, + 218700000, + 221184000, + 221433750, + 223948800, + 225000000, + 226492416, + 226748160, + 227812500, + 229582512, + 230400000, + 233280000, + 234375000, + 235929600, + 236196000, + 238878720, + 239148450, + 240000000, + 241864704, + 243000000, + 244140625, + 245760000, + 246037500, + 248832000, + 250000000, + 251658240, + 251942400, + 253125000, + 254803968, + 255091680, + 256000000, + 258280326, + 259200000, + 262144000, + 262440000, + 263671875, + 265420800, + 265720500, + 268435456, + 268738560, + 270000000, + 272097792, + 273375000, + 276480000, + 279936000, + 281250000, + 283115520, + 283435200, + 284765625, + 286654464, + 286978140, + 288000000, + 291600000, + 292968750, + 294912000, + 295245000, + 298598400, + 300000000, + 301989888, + 302330880, + 303750000, + 306110016, + 307200000, + 307546875, + 311040000, + 312500000, + 314572800, + 314928000, + 316406250, + 318504960, + 318864600, + 320000000, + 322486272, + 324000000, + 327680000, + 328050000, + 331776000, + 332150625, + 335544320, + 335923200, + 337500000, + 339738624, + 340122240, + 341718750, + 344373768, + 345600000, + 349920000, + 351562500, + 353894400, + 354294000, + 358318080, + 358722675, + 360000000, + 362797056, + 364500000, + 368640000, + 369056250, + 373248000, + 375000000, + 377487360, + 377913600, + 379687500, + 382205952, + 382637520, + 384000000, + 387420489, + 388800000, + 390625000, + 393216000, + 393660000, + 398131200, + 398580750, + 400000000, + 402653184, + 403107840, + 405000000, + 408146688, + 409600000, + 410062500, + 414720000, + 419430400, + 419904000, + 421875000, + 424673280, + 425152800, + 429981696, + 430467210, + 432000000, + 437400000, + 439453125, + 442368000, + 442867500, + 447897600, + 450000000, + 452984832, + 453496320, + 455625000, + 459165024, + 460800000, + 466560000, + 468750000, + 471859200, + 472392000, + 474609375, + 477757440, + 478296900, + 480000000, + 483729408, + 486000000, + 488281250, + 491520000, + 492075000, + 497664000, + 500000000, + 503316480, + 503884800, + 506250000, + 509607936, + 510183360, + 512000000, + 512578125, + 516560652, + 518400000, + 524288000, + 524880000, + 527343750, + 530841600, + 531441000, + 536870912, + 537477120, + 540000000, + 544195584, + 546750000, + 552960000, + 553584375, + 559872000, + 562500000, + 566231040, + 566870400, + 569531250, + 573308928, + 573956280, + 576000000, + 583200000, + 585937500, + 589824000, + 590490000, + 597196800, + 597871125, + 600000000, + 603979776, + 604661760, + 607500000, + 612220032, + 614400000, + 615093750, + 622080000, + 625000000, + 629145600, + 629856000, + 632812500, + 637009920, + 637729200, + 640000000, + 644972544, + 645700815, + 648000000, + 655360000, + 656100000, + 663552000, + 664301250, + 671088640, + 671846400, + 675000000, + 679477248, + 680244480, + 683437500, + 688747536, + 691200000, + 699840000, + 703125000, + 707788800, + 708588000, + 716636160, + 717445350, + 720000000, + 725594112, + 729000000, + 732421875, + 737280000, + 738112500, + 746496000, + 750000000, + 754974720, + 755827200, + 759375000, + 764411904, + 765275040, + 768000000, + 774840978, + 777600000, + 781250000, + 786432000, + 787320000, + 791015625, + 796262400, + 797161500, + 800000000, + 805306368, + 806215680, + 810000000, + 816293376, + 819200000, + 820125000, + 829440000, + 838860800, + 839808000, + 843750000, + 849346560, + 850305600, + 854296875, + 859963392, + 860934420, + 864000000, + 874800000, + 878906250, + 884736000, + 885735000, + 895795200, + 900000000, + 905969664, + 906992640, + 911250000, + 918330048, + 921600000, + 922640625, + 933120000, + 937500000, + 943718400, + 944784000, + 949218750, + 955514880, + 956593800, + 960000000, + 967458816, + 972000000, + 976562500, + 983040000, + 984150000, + 995328000, + 996451875, + 1000000000, + 1006632960, + 1007769600, + 1012500000, + 1019215872, + 1020366720, + 1024000000, + 1025156250, + 1033121304, + 1036800000, + 1048576000, + 1049760000, + 1054687500, + 1061683200, + 1062882000, + 1073741824, + 1074954240, + 1076168025, + 1080000000, + 1088391168, + 1093500000, + 1105920000, + 1107168750, + 1119744000, + 1125000000, + 1132462080, + 1133740800, + 1139062500, + 1146617856, + 1147912560, + 1152000000, + 1162261467, + 1166400000, + 1171875000, + 1179648000, + 1180980000, + 1194393600, + 1195742250, + 1200000000, + 1207959552, + 1209323520, + 1215000000, + 1220703125, + 1224440064, + 1228800000, + 1230187500, + 1244160000, + 1250000000, + 1258291200, + 1259712000, + 1265625000, + 1274019840, + 1275458400, + 1280000000, + 1289945088, + 1291401630, + 1296000000, + 1310720000, + 1312200000, + 1318359375, + 1327104000, + 1328602500, + 1342177280, + 1343692800, + 1350000000, + 1358954496, + 1360488960, + 1366875000, + 1377495072, + 1382400000, + 1399680000, + 1406250000, + 1415577600, + 1417176000, + 1423828125, + 1433272320, + 1434890700, + 1440000000, + 1451188224, + 1458000000, + 1464843750, + 1474560000, + 1476225000, + 1492992000, + 1500000000, + 1509949440, + 1511654400, + 1518750000, + 1528823808, + 1530550080, + 1536000000, + 1537734375, + 1549681956, + 1555200000, + 1562500000, + 1572864000, + 1574640000, + 1582031250, + 1592524800, + 1594323000, + 1600000000, + 1610612736, + 1612431360, + 1620000000, + 1632586752, + 1638400000, + 1640250000, + 1658880000, + 1660753125, + 1677721600, + 1679616000, + 1687500000, + 1698693120, + 1700611200, + 1708593750, + 1719926784, + 1721868840, + 1728000000, + 1749600000, + 1757812500, + 1769472000, + 1771470000, + 1791590400, + 1793613375, + 1800000000, + 1811939328, + 1813985280, + 1822500000, + 1836660096, + 1843200000, + 1845281250, + 1866240000, + 1875000000, + 1887436800, + 1889568000, + 1898437500, + 1911029760, + 1913187600, + 1920000000, + 1934917632, + 1937102445, + 1944000000, + 1953125000, + 1966080000, + 1968300000, + 1990656000, + 1992903750, + 2000000000, + 2013265920, + 2015539200, + 2025000000, + 2038431744, + 2040733440, + 2048000000, + 2050312500, + 2066242608, + 2073600000, + 2097152000, + 2099520000, + 2109375000, + 2123366400, 2125764000, ]; export default nthUglyNumber; diff --git a/circle-and-rectangle-overlapping/index.ts b/circle-and-rectangle-overlapping/index.ts index eddf7d1d..e7b408fd 100644 --- a/circle-and-rectangle-overlapping/index.ts +++ b/circle-and-rectangle-overlapping/index.ts @@ -5,7 +5,7 @@ export default function checkOverlap( x1: number, y1: number, x2: number, - y2: number + y2: number, ): boolean { const dx = x1 > xCenter ? x1 - xCenter : x2 < xCenter ? xCenter - x2 : 0; const dy = y1 > yCenter ? y1 - yCenter : y2 < yCenter ? yCenter - y2 : 0; diff --git a/closest-dessert-cost/index.ts b/closest-dessert-cost/index.ts index a5d37831..bba91c7c 100644 --- a/closest-dessert-cost/index.ts +++ b/closest-dessert-cost/index.ts @@ -1,7 +1,7 @@ function closestCost( baseCosts: number[], toppingCosts: number[], - target: number + target: number, ): number { const m = toppingCosts.length; let ret = Infinity; diff --git a/closest-nodes-queries-in-a-binary-search-tree/index.ts b/closest-nodes-queries-in-a-binary-search-tree/index.ts index aa1599de..47eb3c74 100644 --- a/closest-nodes-queries-in-a-binary-search-tree/index.ts +++ b/closest-nodes-queries-in-a-binary-search-tree/index.ts @@ -5,7 +5,7 @@ import { upperBound } from "../maximum-profit-in-job-scheduling/upperBound.ts"; export default function closestNodes( root: TreeNode | null, - queries: number[] + queries: number[], ): number[][] { const nums = inorderTraversal(root); diff --git a/coloring-a-border/index.ts b/coloring-a-border/index.ts index b23b09c8..200906c5 100644 --- a/coloring-a-border/index.ts +++ b/coloring-a-border/index.ts @@ -2,7 +2,7 @@ export default function colorBorder( grid: number[][], row: number, col: number, - color: number + color: number, ): number[][] { const m = grid.length, n = grid[0].length; diff --git a/combination-sum-ii/index.ts b/combination-sum-ii/index.ts index dc40663e..3c4efe5a 100644 --- a/combination-sum-ii/index.ts +++ b/combination-sum-ii/index.ts @@ -1,6 +1,6 @@ export default function combinationSum2( candidates: number[], - target: number + target: number, ): number[][] { candidates.sort((a, b) => -b + a); const ans: number[][] = []; @@ -15,7 +15,7 @@ function dfs( candidates: number[], target: number, path: number[], - output: (path: number[]) => void + output: (path: number[]) => void, ) { if (target === 0) { output(path); @@ -34,7 +34,7 @@ function dfs( candidates.slice(index + 1), target - can, [...path, can], - output + output, ); } } else { diff --git a/combination-sum/index.ts b/combination-sum/index.ts index 92aa94cf..09628b9c 100644 --- a/combination-sum/index.ts +++ b/combination-sum/index.ts @@ -1,6 +1,6 @@ export default function combinationSum( candidates: number[], - target: number + target: number, ): number[][] { candidates.sort((a, b) => -b + a); const ans: number[][] = []; @@ -12,7 +12,7 @@ function dfs( candidates: number[], target: number, path: number[], - output: (path: number[]) => void + output: (path: number[]) => void, ) { if (target === 0) { output(path); @@ -25,7 +25,7 @@ function dfs( index ? candidates.slice(index) : candidates, target - can, [...path, can], - output + output, ); } else { return; diff --git a/combinations/index.ts b/combinations/index.ts index 8007506c..ad7f4c7a 100644 --- a/combinations/index.ts +++ b/combinations/index.ts @@ -37,7 +37,7 @@ function dfs( n: number, k: number, temp: number[], - output: (nums: number[]) => void + output: (nums: number[]) => void, ) { if (temp.length > k) { return; diff --git a/compare-version-numbers/index.ts b/compare-version-numbers/index.ts index fdcdd4f6..888fb40e 100644 --- a/compare-version-numbers/index.ts +++ b/compare-version-numbers/index.ts @@ -1,6 +1,6 @@ export default function compareVersion( version1: string, - version2: string + version2: string, ): number { const a = version1.split(".").map(Number); diff --git a/concatenated-words/index.ts b/concatenated-words/index.ts index 3ad1e42c..a2a83a74 100644 --- a/concatenated-words/index.ts +++ b/concatenated-words/index.ts @@ -2,7 +2,7 @@ import { PrefixTreeInsert } from "../design-add-and-search-words-data-structure/ import { PrefixTree } from "../implement-trie-prefix-tree/PrefixTree.ts"; export default function findAllConcatenatedWordsInADict( - words: string[] + words: string[], ): string[] { const root = PrefixTree(); const ans: string[] = new Array(0); diff --git a/construct-binary-tree-from-inorder-and-postorder-traversal/index.ts b/construct-binary-tree-from-inorder-and-postorder-traversal/index.ts index 7d6ba8b5..da37bc01 100644 --- a/construct-binary-tree-from-inorder-and-postorder-traversal/index.ts +++ b/construct-binary-tree-from-inorder-and-postorder-traversal/index.ts @@ -2,7 +2,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function buildTree( inorder: number[], - postorder: number[] + postorder: number[], ): TreeNode | null { if (inorder.length === 0) return null; let post_idx = postorder.length - 1; diff --git a/construct-binary-tree-from-preorder-and-inorder-traversal/index.ts b/construct-binary-tree-from-preorder-and-inorder-traversal/index.ts index 18765487..2dc4e19b 100644 --- a/construct-binary-tree-from-preorder-and-inorder-traversal/index.ts +++ b/construct-binary-tree-from-preorder-and-inorder-traversal/index.ts @@ -9,7 +9,7 @@ function buildTree(preorder: number[], inorder: number[]): TreeNode | null { pStart: number, pEnd: number, iStart: number, - iEnd: number + iEnd: number, ): TreeNode | null { if (pStart > pEnd) { return null; diff --git a/construct-binary-tree-from-string/index.ts b/construct-binary-tree-from-string/index.ts index d0783060..522fa792 100644 --- a/construct-binary-tree-from-string/index.ts +++ b/construct-binary-tree-from-string/index.ts @@ -12,16 +12,16 @@ function str2tree(s: string): TreeNode | null { .replaceAll("(", ",[") .replaceAll(",]", "]") + "]" - ).replaceAll(",]", "]") + ).replaceAll(",]", "]"), ); } function reviver(value: any): any { return Array.isArray(value) ? { - val: value[0], - left: reviver(value[1]) ?? null, - right: reviver(value[2]) ?? null, - } + val: value[0], + left: reviver(value[1]) ?? null, + right: reviver(value[2]) ?? null, + } : value; } function deserialize(data: string): any { diff --git a/contains-duplicate-ii/index.ts b/contains-duplicate-ii/index.ts index 03a97f30..05505712 100644 --- a/contains-duplicate-ii/index.ts +++ b/contains-duplicate-ii/index.ts @@ -1,6 +1,6 @@ export default function containsNearbyDuplicate( nums: number[], - k: number + k: number, ): boolean { const map: Map = new Map(); return nums.some((num, index) => { diff --git a/contains-duplicate-iii/index.ts b/contains-duplicate-iii/index.ts index e95b95fa..b1089d58 100644 --- a/contains-duplicate-iii/index.ts +++ b/contains-duplicate-iii/index.ts @@ -1,7 +1,7 @@ export default function containsNearbyAlmostDuplicate( nums: number[], k: number, - t: number + t: number, ): boolean { //要查找值<=t则桶的大小为t+1,这样一个桶内的最小值是x,最大值是x+t,桶的大小是t+1 const bucket = t + 1; diff --git a/convert-1d-array-into-2d-array/index.ts b/convert-1d-array-into-2d-array/index.ts index c086b35a..f9e39d13 100644 --- a/convert-1d-array-into-2d-array/index.ts +++ b/convert-1d-array-into-2d-array/index.ts @@ -1,12 +1,12 @@ function construct2DArray( original: number[], m: number, - n: number + n: number, ): number[][] { return original.length === m * n ? Array(m) - .fill(0) - .map((_, i) => original.slice(i * n, i * n + n)) + .fill(0) + .map((_, i) => original.slice(i * n, i * n + n)) : []; } export default construct2DArray; diff --git a/convert-sorted-array-to-binary-search-tree/index.ts b/convert-sorted-array-to-binary-search-tree/index.ts index 25e95bc3..fe20dd4c 100644 --- a/convert-sorted-array-to-binary-search-tree/index.ts +++ b/convert-sorted-array-to-binary-search-tree/index.ts @@ -14,6 +14,6 @@ export default function sortedArrayToBST(nums: number[]): TreeNode | null { if (index >= n) return; index++; - } + }, ); } diff --git a/convert-sorted-list-to-binary-search-tree/index.ts b/convert-sorted-list-to-binary-search-tree/index.ts index 1fddfe80..a2a808ed 100644 --- a/convert-sorted-list-to-binary-search-tree/index.ts +++ b/convert-sorted-list-to-binary-search-tree/index.ts @@ -3,7 +3,7 @@ import { get_length_of_list } from "../reverse-linked-list-ii/get_length_of_list import { buildBST } from "./buildBST.ts"; export default function sortedListbuildBST( - head: ListNode | null + head: ListNode | null, ): TreeNode | null { if (!head) return null; let node: ListNode | null = head; @@ -24,6 +24,6 @@ export default function sortedListbuildBST( if (!node) return; node = node.next; - } + }, ); } diff --git a/coordinate-with-maximum-network-quality/index.ts b/coordinate-with-maximum-network-quality/index.ts index f44e1d56..0b5f7b96 100644 --- a/coordinate-with-maximum-network-quality/index.ts +++ b/coordinate-with-maximum-network-quality/index.ts @@ -1,6 +1,6 @@ export default function bestCoordinate( towers: number[][], - radius: number + radius: number, ): number[] { const xmax = Math.max(...towers.map((a) => a[0])); const ymax = Math.max(...towers.map((a) => a[1])); @@ -15,7 +15,7 @@ export default function bestCoordinate( ( p: [number, number, number], _, - y + y, ): [number, number, number] => { const value: [number, number, number] = [ x, @@ -24,18 +24,18 @@ export default function bestCoordinate( ]; return selectmax(p, value); }, - [0, 0, 0] + [0, 0, 0], ); return selectmax(p, current); }, - [0, 0, 0] + [0, 0, 0], ) .slice(0, 2); } function selectmax( a: [number, number, number], - b: [number, number, number] + b: [number, number, number], ): [number, number, number] { if (a[2] > b[2]) return a; if (a[2] < b[2]) return b; @@ -52,7 +52,7 @@ function calcquality( x: number, y: number, radius: number, - towers: number[][] + towers: number[][], ): number { return towers.reduce((p, [q, w, e]) => { const d = Math.hypot(x - q, y - w); diff --git a/count-all-possible-routes/index.ts b/count-all-possible-routes/index.ts index f0a16b6d..4e077ab8 100644 --- a/count-all-possible-routes/index.ts +++ b/count-all-possible-routes/index.ts @@ -2,7 +2,7 @@ export default function countRoutes( locations: number[], start: number, finish: number, - fuel: number + fuel: number, ): number { const MOD = 1000000007; diff --git a/count-anagrams/index.ts b/count-anagrams/index.ts index c2668c55..f5336298 100644 --- a/count-anagrams/index.ts +++ b/count-anagrams/index.ts @@ -16,7 +16,7 @@ function countAnagrams(s: string): number { } return Number( - (BigInt(ans) * multiplicativeInverse(mul, BigInt(mod))) % BigInt(mod) + (BigInt(ans) * multiplicativeInverse(mul, BigInt(mod))) % BigInt(mod), ); } export default countAnagrams; diff --git a/count-and-say/index.ts b/count-and-say/index.ts index 867b0ded..496e3309 100644 --- a/count-and-say/index.ts +++ b/count-and-say/index.ts @@ -22,7 +22,7 @@ function countAndSay(n: number): string { } else { const index = Array.prototype.findIndex.call( prev, - (v) => v !== start + (v) => v !== start, ); if (index >= 0) { diff --git a/count-complete-tree-nodes/index.ts b/count-complete-tree-nodes/index.ts index 24e71f6e..c346e16e 100644 --- a/count-complete-tree-nodes/index.ts +++ b/count-complete-tree-nodes/index.ts @@ -3,7 +3,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function countNodes( root: TreeNode | null, leftDepth?: number, - rightDepth?: number + rightDepth?: number, ): number { if (root === null) return 0; let left = 0, diff --git a/count-days-spent-together/index.ts b/count-days-spent-together/index.ts index d0cae59c..ed1b671f 100644 --- a/count-days-spent-together/index.ts +++ b/count-days-spent-together/index.ts @@ -2,13 +2,12 @@ export default function countDaysTogether( arriveAlice: string, leaveAlice: string, arriveBob: string, - leaveBob: string + leaveBob: string, ): number { const arrive = arriveAlice > arriveBob ? arriveAlice : arriveBob, leave = leaveAlice < leaveBob ? leaveAlice : leaveBob, - base = - (new Date(`2021-${leave}`).valueOf() - - new Date(`2021-${arrive}`).valueOf()) / + base = (new Date(`2021-${leave}`).valueOf() - + new Date(`2021-${arrive}`).valueOf()) / (24 * 60 * 60 * 1000) + 1; return Math.max(base, 0); diff --git a/count-items-matching-a-rule/index.ts b/count-items-matching-a-rule/index.ts index bb299f7f..d759b53a 100644 --- a/count-items-matching-a-rule/index.ts +++ b/count-items-matching-a-rule/index.ts @@ -1,12 +1,12 @@ export default function countMatches( items: string[][], ruleKey: string, - ruleValue: string + ruleValue: string, ): number { return items.filter( ([t, c, n]) => (ruleKey === "type" && t == ruleValue) || (ruleKey === "color" && c == ruleValue) || - (ruleKey === "name" && n == ruleValue) + (ruleKey === "name" && n == ruleValue), ).length; } diff --git a/count-number-of-bad-pairs/index.ts b/count-number-of-bad-pairs/index.ts index 20284af8..bfd48380 100644 --- a/count-number-of-bad-pairs/index.ts +++ b/count-number-of-bad-pairs/index.ts @@ -6,7 +6,7 @@ function countBadPairs(nums: number[]): number { } const ans = Array.from(cnt.values()).reduce( (a, v) => a + Math.floor((v * (v - 1)) / 2), - 0 + 0, ); return Math.floor((n * (n - 1)) / 2) - ans; } diff --git a/count-subarrays-with-fixed-bounds/index.ts b/count-subarrays-with-fixed-bounds/index.ts index 4b9ad282..c93b0f86 100644 --- a/count-subarrays-with-fixed-bounds/index.ts +++ b/count-subarrays-with-fixed-bounds/index.ts @@ -1,7 +1,7 @@ export default function countSubarrays( nums: number[], minK: number, - maxK: number + maxK: number, ): number { let ans = 0; const n = nums.length; diff --git a/count-the-number-of-consistent-strings/index.ts b/count-the-number-of-consistent-strings/index.ts index 76793394..04f533ce 100644 --- a/count-the-number-of-consistent-strings/index.ts +++ b/count-the-number-of-consistent-strings/index.ts @@ -1,12 +1,12 @@ export default function countConsistentStrings( allowed: string, - words: string[] + words: string[], ): number { const chars = new Set(allowed); return words.reduce( (p, c) => p + Number(Array.prototype.every.call(c, (w) => chars.has(w))), - 0 + 0, ); } diff --git a/count-ways-to-build-good-string/index.ts b/count-ways-to-build-good-string/index.ts index 5f819b2f..34cebcc5 100644 --- a/count-ways-to-build-good-string/index.ts +++ b/count-ways-to-build-good-string/index.ts @@ -2,7 +2,7 @@ function countGoodStrings( low: number, high: number, zero: number, - one: number + one: number, ): number { const dp: number[] = Array(high + 1).fill(0); dp[0] = 1; diff --git a/course-schedule-ii/index.ts b/course-schedule-ii/index.ts index fec6d66e..79275d53 100644 --- a/course-schedule-ii/index.ts +++ b/course-schedule-ii/index.ts @@ -1,6 +1,6 @@ export default function findOrder( numCourses: number, - prerequisites: number[][] + prerequisites: number[][], ): number[] { const dependents: number[][] = new Array(numCourses).fill(0).map(() => []); const indegress: number[] = new Array(numCourses).fill(0); diff --git a/course-schedule/index.ts b/course-schedule/index.ts index c44a2b10..88152adb 100644 --- a/course-schedule/index.ts +++ b/course-schedule/index.ts @@ -1,6 +1,6 @@ export default function canFinish( numCourses: number, - prerequisites: number[][] + prerequisites: number[][], ): boolean { const dependents: Map = new Map(); @@ -14,7 +14,7 @@ export default function canFinish( indegress.set(child, (indegress.get(child) ?? 0) + 1); } const queue: number[] = Array.from(Array(numCourses).fill(0).keys()).filter( - (i) => !indegress.has(i) + (i) => !indegress.has(i), ); let result: number = 0; diff --git a/cousins-in-binary-tree/index.ts b/cousins-in-binary-tree/index.ts index 3aa1fa2c..a023f435 100644 --- a/cousins-in-binary-tree/index.ts +++ b/cousins-in-binary-tree/index.ts @@ -3,7 +3,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function isCousins( root: TreeNode | null, x: number, - y: number + y: number, ): boolean { if (!root) return false; let current_level: { child: TreeNode; parent: TreeNode | null }[] = [ @@ -15,7 +15,7 @@ export default function isCousins( while (current_level.length > 0) { if (current_level.length >= 2) { const values: Map = new Map( - current_level.map((t) => [t.child.val, t.parent]) + current_level.map((t) => [t.child.val, t.parent]), ); if ( values.has(x) && diff --git a/create-target-array-in-the-given-order/index.ts b/create-target-array-in-the-given-order/index.ts index 5d3d2dd5..162b1f26 100644 --- a/create-target-array-in-the-given-order/index.ts +++ b/create-target-array-in-the-given-order/index.ts @@ -1,6 +1,6 @@ export default function createTargetArray( nums: number[], - index: number[] + index: number[], ): number[] { const target: number[] = Array(); target.length = nums.length; diff --git a/deep-dark-fraction/index.ts b/deep-dark-fraction/index.ts index 55712251..5a7b738d 100644 --- a/deep-dark-fraction/index.ts +++ b/deep-dark-fraction/index.ts @@ -8,7 +8,7 @@ export default function fraction(cont: number[]): number[] { new Fraction({ molecular: c, denominator: 1 }), fractionReciprocal(p), ]), - new Fraction({ molecular: 1, denominator: 0 }) + new Fraction({ molecular: 1, denominator: 0 }), ); return [result.molecular, result.denominator]; } diff --git a/delete-node-in-a-bst/index.ts b/delete-node-in-a-bst/index.ts index 0374c749..b983d545 100644 --- a/delete-node-in-a-bst/index.ts +++ b/delete-node-in-a-bst/index.ts @@ -2,7 +2,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function deleteNode( root: TreeNode | null, - key: number + key: number, ): TreeNode | null { if (!root) return null; diff --git a/delete-tree-nodes/index.ts b/delete-tree-nodes/index.ts index d25e614e..47c9c57d 100644 --- a/delete-tree-nodes/index.ts +++ b/delete-tree-nodes/index.ts @@ -1,7 +1,7 @@ export default function deleteTreeNodes( nodes: number, parent: number[], - value: number[] + value: number[], ): number { const children: number[][] = Array.from(parent) .fill(0) @@ -16,12 +16,11 @@ export default function deleteTreeNodes( for (const c of children[node]) { dfs(c); } - sum[node] = - value[node] + children[node].reduce((a, c) => a + sum[c], 0); - count[node] = - sum[node] !== 0 - ? 1 + children[node].reduce((a, c) => a + count[c], 0) - : 0; + sum[node] = value[node] + + children[node].reduce((a, c) => a + sum[c], 0); + count[node] = sum[node] !== 0 + ? 1 + children[node].reduce((a, c) => a + count[c], 0) + : 0; // console.log(node); } const sum: number[] = Array.from(parent).fill(0); diff --git a/delivering-boxes-from-storage-to-ports/index.ts b/delivering-boxes-from-storage-to-ports/index.ts index 0c2bc846..85abfe28 100644 --- a/delivering-boxes-from-storage-to-ports/index.ts +++ b/delivering-boxes-from-storage-to-ports/index.ts @@ -2,7 +2,7 @@ function boxDelivering( boxes: number[][], _portsCount: number, maxBoxes: number, - maxWeight: number + maxWeight: number, ): number { const { min } = Math; const n = boxes.length; diff --git a/design-a-food-rating-system/index.ts b/design-a-food-rating-system/index.ts index ec2966c1..b93670e3 100644 --- a/design-a-food-rating-system/index.ts +++ b/design-a-food-rating-system/index.ts @@ -9,8 +9,7 @@ class FoodRatings { const cuisine = cuisines[index]; const rating = ratings[index]; this.#foodToRating.set(food, rating); - const tree = - this.#cuisineToTree.get(cuisine) ?? + const tree = this.#cuisineToTree.get(cuisine) ?? new AvlTree((a, b) => { const ra = this.#foodToRating.get(a) ?? 0; const rb = this.#foodToRating.get(b) ?? 0; diff --git a/design-an-atm-machine/index.ts b/design-an-atm-machine/index.ts index 3c9e5c57..4bec92a1 100644 --- a/design-an-atm-machine/index.ts +++ b/design-an-atm-machine/index.ts @@ -37,13 +37,13 @@ function ATM(): ATM { if ((changedStore.get(money) ?? 0) > 0 && amount >= money) { const d = Math.min( Math.floor(amount / money), - changedStore.get(money) ?? 0 + changedStore.get(money) ?? 0, ); amount -= money * d; delta.set(money, +d + (delta.get(money) ?? 0)); changedStore.set( money, - -d + (changedStore.get(money) ?? 0) + -d + (changedStore.get(money) ?? 0), ); } } diff --git a/design-an-expression-tree-with-evaluate-function/index.ts b/design-an-expression-tree-with-evaluate-function/index.ts index 6f7e4921..c132bf2a 100644 --- a/design-an-expression-tree-with-evaluate-function/index.ts +++ b/design-an-expression-tree-with-evaluate-function/index.ts @@ -33,7 +33,7 @@ export class Node { constructor( public val: string = "", public left: Node | null = null, - public right: Node | null = null + public right: Node | null = null, ) {} evaluate(): number { if (this.left == null && this.right == null) return Number(this.val); diff --git a/design-circular-deque/index.ts b/design-circular-deque/index.ts index e93754c7..681c4424 100644 --- a/design-circular-deque/index.ts +++ b/design-circular-deque/index.ts @@ -11,7 +11,7 @@ export default interface MyCircularDeque { } export default function MyCircularDeque( - capacity = Infinity + capacity = Infinity, ): MyCircularDeque { if (capacity < 1) throw Error("k greater than or equal one"); const storage = new Map(); diff --git a/design-compressed-string-iterator/index.ts b/design-compressed-string-iterator/index.ts index b55f9aa9..448d71e3 100644 --- a/design-compressed-string-iterator/index.ts +++ b/design-compressed-string-iterator/index.ts @@ -16,7 +16,7 @@ export default class StringIterator { } } export function* RLEGenerator( - encoding: string + encoding: string, ): Generator { for (let i = 0; i < encoding.length; i += 2) { const count = Number(encoding[i + 1]); diff --git a/design-front-middle-back-queue/index.ts b/design-front-middle-back-queue/index.ts index 7a7208e6..13124488 100644 --- a/design-front-middle-back-queue/index.ts +++ b/design-front-middle-back-queue/index.ts @@ -21,8 +21,7 @@ export default class FrontMiddleBackQueue { // console.log(this) if (this.#queue.length === 0) return -1; // console.log(this.queue.length) - const mid = - Math.floor(this.#queue.length / 2) - + const mid = Math.floor(this.#queue.length / 2) - Number(!(this.#queue.length % 2)); // console.log(mid) const result = this.#queue[mid]; diff --git a/design-in-memory-file-system/index.ts b/design-in-memory-file-system/index.ts index 7cc3f04a..a2d0a6c8 100644 --- a/design-in-memory-file-system/index.ts +++ b/design-in-memory-file-system/index.ts @@ -2,7 +2,7 @@ class Node { constructor( public type: "file" | "folder" = "folder", public content: string = "", - public children: Set = new Set() + public children: Set = new Set(), ) {} } export { Node }; diff --git a/design-movie-rental-system/index.ts b/design-movie-rental-system/index.ts index 47bc7409..181ecd12 100644 --- a/design-movie-rental-system/index.ts +++ b/design-movie-rental-system/index.ts @@ -15,8 +15,7 @@ export default class MovieRentingSystem { for (const [shop, movie, price] of entries) { this.#price.set([shop, movie], price); - const tree = - this.#valid.get(movie) ?? + const tree = this.#valid.get(movie) ?? new BinarySearchTree((a, b) => a[0] === b[0] ? a[1] - b[1] : a[0] - b[0] ); @@ -70,7 +69,7 @@ export default class MovieRentingSystem { } } export function* InOrderIterator( - root: BinarySearchTreeNode | null + root: BinarySearchTreeNode | null, ): Generator> { if (!root) return; yield* InOrderIterator(root.getLeft()); diff --git a/design-parking-system/index.ts b/design-parking-system/index.ts index d1a422c2..405e0a3b 100644 --- a/design-parking-system/index.ts +++ b/design-parking-system/index.ts @@ -5,7 +5,7 @@ export default ParkingSystem; function ParkingSystem( big: number, medium: number, - small: number + small: number, ): ParkingSystem { const park = new Map(); park.set(1, big); diff --git a/design-twitter/index.ts b/design-twitter/index.ts index 65ffe122..a314e808 100644 --- a/design-twitter/index.ts +++ b/design-twitter/index.ts @@ -51,8 +51,8 @@ export default class Twitter { } follow(followerId: number, followeeId: number): void { - const followee = - this.#follower_to_followees.get(followerId) ?? new Set(); + const followee = this.#follower_to_followees.get(followerId) ?? + new Set(); followee.add(followeeId); this.#follower_to_followees.set(followerId, followee); diff --git a/determine-if-string-halves-are-alike/index.ts b/determine-if-string-halves-are-alike/index.ts index 9d3c02ed..f73b8c5f 100644 --- a/determine-if-string-halves-are-alike/index.ts +++ b/determine-if-string-halves-are-alike/index.ts @@ -1,11 +1,12 @@ export default function halvesAreAlike(s: string): boolean { const set = new Set(["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]); - const cnt = [...s.slice(0, s.length / 2)].filter((element) => - set.has(element) - ).length; + const cnt = + [...s.slice(0, s.length / 2)].filter((element) => set.has(element)) + .length; return ( cnt === - [...s.slice(s.length / 2)].filter((element) => set.has(element)).length + [...s.slice(s.length / 2)].filter((element) => set.has(element)) + .length ); } diff --git a/determine-if-two-events-have-conflict/index.ts b/determine-if-two-events-have-conflict/index.ts index 23aa0443..50818b15 100644 --- a/determine-if-two-events-have-conflict/index.ts +++ b/determine-if-two-events-have-conflict/index.ts @@ -1,6 +1,6 @@ export default function haveConflict( event1: string[], - event2: string[] + event2: string[], ): boolean { return event1[0] <= event2[1] && event1[1] >= event2[0]; } diff --git a/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/index.ts b/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/index.ts index 67a5b0fb..95142b4f 100644 --- a/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/index.ts +++ b/diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof/index.ts @@ -2,6 +2,6 @@ import { groupBy } from "../deps.ts"; export default function exchange(nums: number[]): number[] { return Object.values( - groupBy(nums, (a) => Number(!(a % 2))) + groupBy(nums, (a) => Number(!(a % 2))), ).flat() as number[]; } diff --git a/different-ways-to-add-parentheses/index.ts b/different-ways-to-add-parentheses/index.ts index da2d1ce3..fcb8fded 100644 --- a/different-ways-to-add-parentheses/index.ts +++ b/different-ways-to-add-parentheses/index.ts @@ -4,16 +4,16 @@ export default function diffWaysToCompute(expression: string): number[] { } const regexp = /(?[\+\-\*])|(?\d+)/g; const groups = Array.from(expression.matchAll(regexp)).map( - (a) => a.groups + (a) => a.groups, ) as unknown as ( | { - digit: string; - operator?: undefined; - } + digit: string; + operator?: undefined; + } | { - digit?: undefined; - operator: string; - } + digit?: undefined; + operator: string; + } )[]; const ans: number[] = diffWaysCalc(groups); return ans; @@ -21,14 +21,14 @@ export default function diffWaysToCompute(expression: string): number[] { function diffWaysCalc( groups: ( | { - digit: number | string; - operator?: undefined; - } + digit: number | string; + operator?: undefined; + } | { - digit?: undefined; - operator: string; - } - )[] + digit?: undefined; + operator: string; + } + )[], ): number[] { if (groups.length === 1) { return [Number(groups[0].digit)]; @@ -52,14 +52,14 @@ function diffWaysCalc( function calc_three( groups: ( | { - digit: number | string; - operator?: undefined; - } + digit: number | string; + operator?: undefined; + } | { - digit?: undefined; - operator: string; - } - )[] + digit?: undefined; + operator: string; + } + )[], ): number { if (groups.length === 3) { const [a, b, c] = groups; diff --git a/distance-between-bus-stops/index.ts b/distance-between-bus-stops/index.ts index d490d749..d6380554 100644 --- a/distance-between-bus-stops/index.ts +++ b/distance-between-bus-stops/index.ts @@ -3,7 +3,7 @@ import { groupBy, sum } from "../deps.ts"; function distanceBetweenBusStops( distance: number[], start: number, - destination: number + destination: number, ): number { [start, destination] = [ Math.min(start, destination), @@ -16,11 +16,11 @@ function distanceBetweenBusStops( ...Object.values( groupBy( Array.from(distance.entries()), - ([index]) => start <= index && index < destination - ) + ([index]) => start <= index && index < destination, + ), // deno-lint-ignore ban-ts-comment //@ts-ignore - ).map((value) => sum(value.map((a) => a[1]))) + ).map((value) => sum(value.map((a) => a[1]))), ); } export default distanceBetweenBusStops; diff --git a/distinct-subsequences/index.ts b/distinct-subsequences/index.ts index 43f33191..48126545 100644 --- a/distinct-subsequences/index.ts +++ b/distinct-subsequences/index.ts @@ -20,10 +20,9 @@ function numDistinct(s: string, t: string): number { for (let i = 1; i <= m; i++) { for (let j = 1; j <= n; j++) { - dp[i][j] = - s[j - 1] === t[i - 1] - ? dp[i - 1][j - 1] + dp[i][j - 1] - : dp[i][j - 1]; + dp[i][j] = s[j - 1] === t[i - 1] + ? dp[i - 1][j - 1] + dp[i][j - 1] + : dp[i][j - 1]; } } diff --git a/divide-a-string-into-groups-of-size-k/index.ts b/divide-a-string-into-groups-of-size-k/index.ts index 61e8e33f..0eeaefc4 100644 --- a/divide-a-string-into-groups-of-size-k/index.ts +++ b/divide-a-string-into-groups-of-size-k/index.ts @@ -1,7 +1,7 @@ export default function divideString( s: string, k: number, - fill: string + fill: string, ): string[] { const str = s.length % k ? s.padEnd(Math.ceil(s.length / k) * k, fill) : s; diff --git a/dungeon-game/index.ts b/dungeon-game/index.ts index e4d032c1..bdec7fe2 100644 --- a/dungeon-game/index.ts +++ b/dungeon-game/index.ts @@ -11,7 +11,7 @@ export default function calculateMinimumHP(dungeon: number[][]): number { for (let j = n - 1; j >= 0; j--) { dp[i][j] = Math.max( 1, - Math.min(dp[i][j + 1], dp[i + 1][j]) - dungeon[i][j] + Math.min(dp[i][j + 1], dp[i + 1][j]) - dungeon[i][j], ); } } diff --git a/edit-distance/index.ts b/edit-distance/index.ts index 268352e6..b5e07494 100644 --- a/edit-distance/index.ts +++ b/edit-distance/index.ts @@ -1,6 +1,7 @@ function minDistance(word1: string, word2: string): number { - const dp: number[][] = Array.from(Array(word1.length + 1), () => - Array(word2.length + 1).fill(0) + const dp: number[][] = Array.from( + Array(word1.length + 1), + () => Array(word2.length + 1).fill(0), ); for (let i = 1; i <= word1.length; i++) { @@ -19,7 +20,7 @@ function minDistance(word1: string, word2: string): number { dp[i][j] = Math.min( dp[i - 1][j] + 1, dp[i][j - 1] + 1, - dp[i - 1][j - 1] + 1 + dp[i - 1][j - 1] + 1, ); } } diff --git a/er-cha-shu-ren-wu-diao-du/index.ts b/er-cha-shu-ren-wu-diao-du/index.ts index c4522220..a88f285d 100644 --- a/er-cha-shu-ren-wu-diao-du/index.ts +++ b/er-cha-shu-ren-wu-diao-du/index.ts @@ -16,8 +16,8 @@ function execTime(node: TreeNode | null): [number, number] { // 左右子树节点之和 const sum = leftTime[1] + rightTime[1]; // 当前节点执行完的最小消耗时间 - const minTime = - Math.max(Math.max(leftTime[0], rightTime[0]), sum / 2) + node.val; + const minTime = Math.max(Math.max(leftTime[0], rightTime[0]), sum / 2) + + node.val; return [minTime, sum + node.val]; } export default minimalExecTime; diff --git a/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/index.ts b/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/index.ts index d448f36a..2d1560c6 100644 --- a/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/index.ts +++ b/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/index.ts @@ -9,7 +9,7 @@ function kthLargest(root: TreeNode | null, k: number): number { throw Error("unreachable"); } export function* reverseInOrderIterator( - root: TreeNode | null + root: TreeNode | null, ): Generator { if (!root) { return; diff --git a/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/index.ts b/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/index.ts index 8b1e83ea..1570a178 100644 --- a/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/index.ts +++ b/er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof/index.ts @@ -3,7 +3,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; // } export default function treeToDoublyList( - root: TreeNode | null + root: TreeNode | null, ): TreeNode | null { if (!root) return null; const tree = new TreeNode(); diff --git a/evaluate-division/index.ts b/evaluate-division/index.ts index 543b0b6d..008096f1 100644 --- a/evaluate-division/index.ts +++ b/evaluate-division/index.ts @@ -1,7 +1,7 @@ export default function calcEquation( equations: string[][], values: number[], - queries: string[][] + queries: string[][], ): number[] { const variables = new Set(); diff --git a/excel-sheet-column-number/index.ts b/excel-sheet-column-number/index.ts index 796758b0..847c5f76 100644 --- a/excel-sheet-column-number/index.ts +++ b/excel-sheet-column-number/index.ts @@ -2,5 +2,5 @@ export default function titleToNumber(columnTitle: string): number { return columnTitle.length === 1 ? columnTitle.charCodeAt(0) - "A".charCodeAt(0) + 1 : titleToNumber(columnTitle.at(-1) ?? "") + - 26 * titleToNumber(columnTitle.slice(0, -1)); + 26 * titleToNumber(columnTitle.slice(0, -1)); } diff --git a/excel-sheet-column-title/index.ts b/excel-sheet-column-title/index.ts index fad98b16..455545c8 100644 --- a/excel-sheet-column-title/index.ts +++ b/excel-sheet-column-title/index.ts @@ -1,6 +1,6 @@ export default function convertToTitle(columnNumber: number): string { return columnNumber > 26 ? convertToTitle(Math.floor((columnNumber - 1) / 26)) + - convertToTitle(((columnNumber - 1) % 26) + 1) + convertToTitle(((columnNumber - 1) % 26) + 1) : String.fromCharCode("A".charCodeAt(0) + columnNumber - 1); } diff --git a/expressive-words/index.ts b/expressive-words/index.ts index 969adf36..4f92f105 100644 --- a/expressive-words/index.ts +++ b/expressive-words/index.ts @@ -4,7 +4,7 @@ export default function expressiveWords(s: string, words: string[]): number { (s.match(/([a-z])\1*/g) ?? []) .map((m) => (m.length >= 3 ? m[0] + `{1,${m.length}}` : m)) .join("") + - "$" + "$", ); return words.filter((w) => re.test(w)).length; diff --git a/filling-bookcase-shelves/index.ts b/filling-bookcase-shelves/index.ts index 40c73af0..69ee008e 100644 --- a/filling-bookcase-shelves/index.ts +++ b/filling-bookcase-shelves/index.ts @@ -1,6 +1,6 @@ export default function minHeightShelves( books: number[][], - shelfWidth: number + shelfWidth: number, ): number { const dp = Array(books.length + 1).fill(Infinity); dp[0] = 0; diff --git a/final-value-of-variable-after-performing-operations/index.ts b/final-value-of-variable-after-performing-operations/index.ts index 10642424..f2cfcc10 100644 --- a/final-value-of-variable-after-performing-operations/index.ts +++ b/final-value-of-variable-after-performing-operations/index.ts @@ -1,8 +1,8 @@ export default function finalValueAfterOperations( - operations: string[] + operations: string[], ): number { return operations.reduce( (p, v) => (["X++", "++X"].includes(v) ? p + 1 : p - 1), - 0 + 0, ); } diff --git a/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/index.ts b/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/index.ts index 81ff428d..767c4118 100644 --- a/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/index.ts +++ b/find-a-corresponding-node-of-a-binary-tree-in-a-clone-of-that-tree/index.ts @@ -3,7 +3,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function getTargetCopy( original: TreeNode | null, cloned: TreeNode | null, - target: TreeNode | null + target: TreeNode | null, ): TreeNode | null { if (!target || !cloned) return null; if (target.val === cloned.val) return cloned; diff --git a/find-all-good-indices/index.ts b/find-all-good-indices/index.ts index 02a7bc38..385891ad 100644 --- a/find-all-good-indices/index.ts +++ b/find-all-good-indices/index.ts @@ -19,14 +19,16 @@ export default function goodIndices(nums: number[], k: number): number[] { for (let i = 0; i < post.length; i++) { if (i === 0) { for (let j = n - 2; j > n - k - 1; j--) { - post[post.length - 1 - i] = - nums[j] <= nums[j + 1] ? post[post.length - 1 - i] + 1 : 1; + post[post.length - 1 - i] = nums[j] <= nums[j + 1] + ? post[post.length - 1 - i] + 1 + : 1; } } else { const j = nums.length - i - k; - post[post.length - 1 - i] = - nums[j] <= nums[j + 1] ? post[post.length - i] + 1 : 1; + post[post.length - 1 - i] = nums[j] <= nums[j + 1] + ? post[post.length - i] + 1 + : 1; } } diff --git a/find-and-replace-pattern/index.ts b/find-and-replace-pattern/index.ts index febd0523..0088053b 100644 --- a/find-and-replace-pattern/index.ts +++ b/find-and-replace-pattern/index.ts @@ -16,7 +16,8 @@ function findAndReplacePattern(words: string[], pattern: string): string[] { const model = getModel(pattern); return words.filter( (word) => - word.length === pattern.length && ArrayEquals(model, getModel(word)) + word.length === pattern.length && + ArrayEquals(model, getModel(word)), ); } function ArrayEquals(a: Array, b: Array): boolean { diff --git a/find-closest-lcci/index.ts b/find-closest-lcci/index.ts index 4501b95e..8a6a5a8d 100644 --- a/find-closest-lcci/index.ts +++ b/find-closest-lcci/index.ts @@ -1,7 +1,7 @@ export default function findClosest( words: string[], word1: string, - word2: string + word2: string, ): number { let ans = words.length; let p1 = -Infinity; diff --git a/find-if-path-exists-in-graph/index.ts b/find-if-path-exists-in-graph/index.ts index 2b0ac5e9..f2cb18ab 100644 --- a/find-if-path-exists-in-graph/index.ts +++ b/find-if-path-exists-in-graph/index.ts @@ -4,7 +4,7 @@ export default function validPath( n: number, edges: number[][], source: number, - destination: number + destination: number, ): boolean { if (source === destination) return true; if (edges.length === 0) return false; diff --git a/find-k-closest-elements/index.ts b/find-k-closest-elements/index.ts index 25e9ef4f..4e525d6b 100644 --- a/find-k-closest-elements/index.ts +++ b/find-k-closest-elements/index.ts @@ -1,7 +1,7 @@ export default function findClosestElements( arr: number[], k: number, - x: number + x: number, ): number[] { const size = arr.length; let left = 0; diff --git a/find-k-pairs-with-smallest-sums/index.ts b/find-k-pairs-with-smallest-sums/index.ts index fa4547c5..9a4c8881 100644 --- a/find-k-pairs-with-smallest-sums/index.ts +++ b/find-k-pairs-with-smallest-sums/index.ts @@ -1,13 +1,13 @@ function kSmallestPairs( nums1: number[], nums2: number[], - k: number + k: number, ): number[][] { const res: number[][] = []; const m = nums1.length, n = nums2.length; const pq = new Heap<[number, number]>( - (a, b) => nums1[a[0]] + nums2[a[1]] - nums1[b[0]] - nums2[b[1]] + (a, b) => nums1[a[0]] + nums2[a[1]] - nums1[b[0]] - nums2[b[1]], ); for (const i of Array(Math.min(k, m)).keys()) { pq.push([i, 0]); diff --git a/find-leaves-of-binary-tree/index.ts b/find-leaves-of-binary-tree/index.ts index 1ccff76a..ed03bfeb 100644 --- a/find-leaves-of-binary-tree/index.ts +++ b/find-leaves-of-binary-tree/index.ts @@ -37,7 +37,7 @@ function dfs( parent: null | TreeNode, leaves: Set, parents: Map, - children: Map + children: Map, ) { if (!root) return; if (!root.left && !root.right) { diff --git a/find-nearest-point-that-has-the-same-x-or-y-coordinate/index.ts b/find-nearest-point-that-has-the-same-x-or-y-coordinate/index.ts index 2b0473a1..7f5aaa8f 100644 --- a/find-nearest-point-that-has-the-same-x-or-y-coordinate/index.ts +++ b/find-nearest-point-that-has-the-same-x-or-y-coordinate/index.ts @@ -4,7 +4,7 @@ function nearestValidPoint(x: number, y: number, points: number[][]): number { (x === a || y === b) && Math.abs(x - a) + Math.abs(y - b) < d ? [i, Math.abs(x - a) + Math.abs(y - b)] : [p, d], - [-1, Infinity] + [-1, Infinity], )[0]; } export default nearestValidPoint; diff --git a/find-peak-element/index.ts b/find-peak-element/index.ts index 2b03d222..34c4af8d 100644 --- a/find-peak-element/index.ts +++ b/find-peak-element/index.ts @@ -10,7 +10,7 @@ export default function findPeakElement(nums: number[]): number { return nums[index] ?? -Infinity; } - for (let i = 0, j = nums.length - 1; i <= j; ) { + for (let i = 0, j = nums.length - 1; i <= j;) { const m = Math.floor((i + j) / 2); // console.log(i, j, m); if (nums[m] > get(m + 1) && nums[m] > get(m - 1)) { diff --git a/find-positive-integer-solution-for-a-given-equation/index.ts b/find-positive-integer-solution-for-a-given-equation/index.ts index 6b9b8301..56da7ac4 100644 --- a/find-positive-integer-solution-for-a-given-equation/index.ts +++ b/find-positive-integer-solution-for-a-given-equation/index.ts @@ -6,7 +6,7 @@ function findSolution(customfunction: CustomFunction, z: number): number[][] { if (z < min || z > max) return []; const res: number[][] = []; - for (let i = 1, j = 1000; i <= 1000 && j >= 1; ) { + for (let i = 1, j = 1000; i <= 1000 && j >= 1;) { const diff = customfunction.f(i, j) - z; if (diff === 0) { res.push([i, j]); diff --git a/find-servers-that-handled-most-number-of-requests/index.ts b/find-servers-that-handled-most-number-of-requests/index.ts index 9fc811e7..36a0d42a 100644 --- a/find-servers-that-handled-most-number-of-requests/index.ts +++ b/find-servers-that-handled-most-number-of-requests/index.ts @@ -4,7 +4,7 @@ import { AvlTree, Heap } from "../deps.ts"; function busiestServers( k: number, arrival: number[], - load: number[] + load: number[], ): number[] { const cnts = new Map(); const pq = new Heap<[number, number]>((a, b) => a[0] - b[0]); diff --git a/find-smallest-letter-greater-than-target/index.ts b/find-smallest-letter-greater-than-target/index.ts index cd0ced00..31a6860f 100644 --- a/find-smallest-letter-greater-than-target/index.ts +++ b/find-smallest-letter-greater-than-target/index.ts @@ -1,6 +1,6 @@ export default function nextGreatestLetter( letters: string[], - target: string + target: string, ): string { const length = letters.length; if (target >= letters[length - 1]) { diff --git a/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/index.ts b/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/index.ts index b6bd56a0..7a3ae6c9 100644 --- a/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/index.ts +++ b/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/index.ts @@ -1,7 +1,7 @@ export default function findTheCity( n: number, edges: number[][], - distanceThreshold: number + distanceThreshold: number, ): number { const dp: number[][] = Array(n) .fill(0) diff --git a/finding-3-digit-even-numbers/index.ts b/finding-3-digit-even-numbers/index.ts index 85b547fc..a779f975 100644 --- a/finding-3-digit-even-numbers/index.ts +++ b/finding-3-digit-even-numbers/index.ts @@ -8,7 +8,7 @@ function findEvenNumbers(digits: number[]): number[] { .map((_, i) => 100 + i * 2) .filter((n) => [...counter(n.toString())].every( - ([key, value]) => (cnt.get(Number(key)) ?? 0) >= value + ([key, value]) => (cnt.get(Number(key)) ?? 0) >= value, ) ); } diff --git a/first-letter-to-appear-twice/index.ts b/first-letter-to-appear-twice/index.ts index 68cfa4aa..3dfa3941 100644 --- a/first-letter-to-appear-twice/index.ts +++ b/first-letter-to-appear-twice/index.ts @@ -2,7 +2,7 @@ function repeatedCharacter(s: string): string { let bitset = 0n; for (const char of s) { const num = BigInt( - 1n << BigInt(char.charCodeAt(0) - "a".charCodeAt(0) + 1) + 1n << BigInt(char.charCodeAt(0) - "a".charCodeAt(0) + 1), ); if (bitset & num) { return char; diff --git a/flatten-nested-list-iterator/index.ts b/flatten-nested-list-iterator/index.ts index c42669de..6264488a 100644 --- a/flatten-nested-list-iterator/index.ts +++ b/flatten-nested-list-iterator/index.ts @@ -1,7 +1,7 @@ import { NestedInteger } from "../mini-parser/NestedInteger.ts"; export function* NestedIntegerIterator( - nestedList: NestedInteger[] + nestedList: NestedInteger[], ): Generator { for (const nestedInteger of nestedList) { if (nestedInteger.isInteger()) { diff --git a/flood-fill/index.ts b/flood-fill/index.ts index f307901f..c1f15c71 100644 --- a/flood-fill/index.ts +++ b/flood-fill/index.ts @@ -2,7 +2,7 @@ export default function floodFill( image: number[][], sr: number, sc: number, - newColor: number + newColor: number, ): number[][] { if (newColor === image[sr][sc]) return image; const currColor = image[sr][sc]; @@ -20,7 +20,7 @@ function dfs( sr: number, sc: number, oldColor: number, - newColor: number + newColor: number, ) { const row = image.length; const col = image[0].length; diff --git a/form-array-by-concatenating-subarrays-of-another-array/index.ts b/form-array-by-concatenating-subarrays-of-another-array/index.ts index c40ad8a6..3834cd2b 100644 --- a/form-array-by-concatenating-subarrays-of-another-array/index.ts +++ b/form-array-by-concatenating-subarrays-of-another-array/index.ts @@ -1,6 +1,6 @@ function canChoose(groups: number[][], nums: number[]): boolean { let i = 0; - for (let k = 0; k < nums.length && i < groups.length; ) { + for (let k = 0; k < nums.length && i < groups.length;) { if (check(groups[i], nums, k)) { k += groups[i].length; i++; diff --git a/fraction-addition-and-subtraction/index.ts b/fraction-addition-and-subtraction/index.ts index 9dfb2b6c..63f38668 100644 --- a/fraction-addition-and-subtraction/index.ts +++ b/fraction-addition-and-subtraction/index.ts @@ -5,7 +5,7 @@ import { parseFraction } from "./parseFraction.ts"; export function fractionAdd(fractions: Fraction[]): Fraction { const denominator = deduplication( - fractions.map((f) => f.denominator) + fractions.map((f) => f.denominator), ).reduce((a, b) => a * b); const molecular = fractions .map((f) => (f.sign * f.molecular * denominator) / f.denominator) diff --git a/fraction-to-recurring-decimal/index.ts b/fraction-to-recurring-decimal/index.ts index 3530c06a..8d9f33ce 100644 --- a/fraction-to-recurring-decimal/index.ts +++ b/fraction-to-recurring-decimal/index.ts @@ -2,7 +2,7 @@ import { absBigint } from "./abs_bigint.ts"; export default function fractionToDecimal( numerator: number, - denominator: number + denominator: number, ): string { let a = BigInt(numerator); let b = BigInt(denominator); diff --git a/generate-random-point-in-a-circle/index.ts b/generate-random-point-in-a-circle/index.ts index 18a4086a..7b6093b1 100644 --- a/generate-random-point-in-a-circle/index.ts +++ b/generate-random-point-in-a-circle/index.ts @@ -1,7 +1,7 @@ export default function Solution( radius: number, x_center: number, - y_center: number + y_center: number, ) { return { randPoint(): number[] { diff --git a/get-kth-magic-number-lcci/index.ts b/get-kth-magic-number-lcci/index.ts index 3ee56329..4de51f47 100644 --- a/get-kth-magic-number-lcci/index.ts +++ b/get-kth-magic-number-lcci/index.ts @@ -2,87 +2,657 @@ export default function getKthMagicNumber(k: number): number { return cache[k - 1] ?? 1; } const cache = [ - 1, 3, 5, 7, 9, 15, 21, 25, 27, 35, 45, 49, 63, 75, 81, 105, 125, 135, 147, - 175, 189, 225, 243, 245, 315, 343, 375, 405, 441, 525, 567, 625, 675, 729, - 735, 875, 945, 1029, 1125, 1215, 1225, 1323, 1575, 1701, 1715, 1875, 2025, - 2187, 2205, 2401, 2625, 2835, 3087, 3125, 3375, 3645, 3675, 3969, 4375, - 4725, 5103, 5145, 5625, 6075, 6125, 6561, 6615, 7203, 7875, 8505, 8575, - 9261, 9375, 10125, 10935, 11025, 11907, 12005, 13125, 14175, 15309, 15435, - 15625, 16807, 16875, 18225, 18375, 19683, 19845, 21609, 21875, 23625, 25515, - 25725, 27783, 28125, 30375, 30625, 32805, 33075, 35721, 36015, 39375, 42525, - 42875, 45927, 46305, 46875, 50421, 50625, 54675, 55125, 59049, 59535, 60025, - 64827, 65625, 70875, 76545, 77175, 78125, 83349, 84035, 84375, 91125, 91875, - 98415, 99225, 107163, 108045, 109375, 117649, 118125, 127575, 128625, - 137781, 138915, 140625, 151263, 151875, 153125, 164025, 165375, 177147, - 178605, 180075, 194481, 196875, 212625, 214375, 229635, 231525, 234375, - 250047, 252105, 253125, 273375, 275625, 295245, 297675, 300125, 321489, - 324135, 328125, 352947, 354375, 382725, 385875, 390625, 413343, 416745, - 420175, 421875, 453789, 455625, 459375, 492075, 496125, 531441, 535815, - 540225, 546875, 583443, 588245, 590625, 637875, 643125, 688905, 694575, - 703125, 750141, 756315, 759375, 765625, 820125, 823543, 826875, 885735, - 893025, 900375, 964467, 972405, 984375, 1058841, 1063125, 1071875, 1148175, - 1157625, 1171875, 1240029, 1250235, 1260525, 1265625, 1361367, 1366875, - 1378125, 1476225, 1488375, 1500625, 1594323, 1607445, 1620675, 1640625, - 1750329, 1764735, 1771875, 1913625, 1929375, 1953125, 2066715, 2083725, - 2100875, 2109375, 2250423, 2268945, 2278125, 2296875, 2460375, 2470629, - 2480625, 2657205, 2679075, 2701125, 2734375, 2893401, 2917215, 2941225, - 2953125, 3176523, 3189375, 3215625, 3444525, 3472875, 3515625, 3720087, - 3750705, 3781575, 3796875, 3828125, 4084101, 4100625, 4117715, 4134375, - 4428675, 4465125, 4501875, 4782969, 4822335, 4862025, 4921875, 5250987, - 5294205, 5315625, 5359375, 5740875, 5764801, 5788125, 5859375, 6200145, - 6251175, 6302625, 6328125, 6751269, 6806835, 6834375, 6890625, 7381125, - 7411887, 7441875, 7503125, 7971615, 8037225, 8103375, 8203125, 8680203, - 8751645, 8823675, 8859375, 9529569, 9568125, 9646875, 9765625, 10333575, - 10418625, 10504375, 10546875, 11160261, 11252115, 11344725, 11390625, - 11484375, 12252303, 12301875, 12353145, 12403125, 13286025, 13395375, - 13505625, 13671875, 14348907, 14467005, 14586075, 14706125, 14765625, - 15752961, 15882615, 15946875, 16078125, 17222625, 17294403, 17364375, - 17578125, 18600435, 18753525, 18907875, 18984375, 19140625, 20253807, - 20420505, 20503125, 20588575, 20671875, 22143375, 22235661, 22325625, - 22509375, 23914845, 24111675, 24310125, 24609375, 26040609, 26254935, - 26471025, 26578125, 26796875, 28588707, 28704375, 28824005, 28940625, - 29296875, 31000725, 31255875, 31513125, 31640625, 33480783, 33756345, - 34034175, 34171875, 34453125, 36756909, 36905625, 37059435, 37209375, - 37515625, 39858075, 40186125, 40353607, 40516875, 41015625, 43046721, - 43401015, 43758225, 44118375, 44296875, 47258883, 47647845, 47840625, - 48234375, 48828125, 51667875, 51883209, 52093125, 52521875, 52734375, - 55801305, 56260575, 56723625, 56953125, 57421875, 60761421, 61261515, - 61509375, 61765725, 62015625, 66430125, 66706983, 66976875, 67528125, - 68359375, 71744535, 72335025, 72930375, 73530625, 73828125, 78121827, - 78764805, 79413075, 79734375, 80390625, 85766121, 86113125, 86472015, - 86821875, 87890625, 93002175, 93767625, 94539375, 94921875, 95703125, - 100442349, 101269035, 102102525, 102515625, 102942875, 103359375, 110270727, - 110716875, 111178305, 111628125, 112546875, 119574225, 120558375, 121060821, - 121550625, 123046875, 129140163, 130203045, 131274675, 132355125, 132890625, - 133984375, 141776649, 142943535, 143521875, 144120025, 144703125, 146484375, - 155003625, 155649627, 156279375, 157565625, 158203125, 167403915, 168781725, - 170170875, 170859375, 172265625, 182284263, 183784545, 184528125, 185297175, - 186046875, 187578125, 199290375, 200120949, 200930625, 201768035, 202584375, - 205078125, 215233605, 217005075, 218791125, 220591875, 221484375, 234365481, - 236294415, 238239225, 239203125, 241171875, 244140625, 257298363, 258339375, - 259416045, 260465625, 262609375, 263671875, 279006525, 281302875, 282475249, - 283618125, 284765625, 287109375, 301327047, 303807105, 306307575, 307546875, - 308828625, 310078125, 330812181, 332150625, 333534915, 334884375, 337640625, - 341796875, 358722675, 361675125, 363182463, 364651875, 367653125, 369140625, - 387420489, 390609135, 393824025, 397065375, 398671875, 401953125, 425329947, - 428830605, 430565625, 432360075, 434109375, 439453125, 465010875, 466948881, - 468838125, 472696875, 474609375, 478515625, 502211745, 506345175, 510512625, - 512578125, 514714375, 516796875, 546852789, 551353635, 553584375, 555891525, - 558140625, 562734375, 597871125, 600362847, 602791875, 605304105, 607753125, - 615234375, 645700815, 651015225, 656373375, 661775625, 664453125, 669921875, - 703096443, 708883245, 714717675, 717609375, 720600125, 723515625, 732421875, - 771895089, 775018125, 778248135, 781396875, 787828125, 791015625, 837019575, - 843908625, 847425747, 850854375, 854296875, 861328125, 903981141, 911421315, - 918922725, 922640625, 926485875, 930234375, 937890625, 992436543, 996451875, - 1000604745, 1004653125, 1008840175, 1012921875, 1025390625, 1076168025, - 1085025375, 1089547389, 1093955625, 1102959375, 1107421875, 1162261467, - 1171827405, 1181472075, 1191196125, 1196015625, 1205859375, 1220703125, - 1275989841, 1286491815, 1291696875, 1297080225, 1302328125, 1313046875, - 1318359375, 1395032625, 1400846643, 1406514375, 1412376245, 1418090625, - 1423828125, 1435546875, 1506635235, 1519035525, 1531537875, 1537734375, - 1544143125, 1550390625, 1640558367, 1654060905, 1660753125, 1667674575, - 1674421875, 1688203125, 1708984375, 1793613375, 1801088541, 1808375625, - 1815912315, 1823259375, 1838265625, 1845703125, 1937102445, 1953045675, - 1969120125, 1977326743, 1985326875, 1993359375, 2009765625, 2109289329, - 2126649735, 2144153025, 2152828125, + 1, + 3, + 5, + 7, + 9, + 15, + 21, + 25, + 27, + 35, + 45, + 49, + 63, + 75, + 81, + 105, + 125, + 135, + 147, + 175, + 189, + 225, + 243, + 245, + 315, + 343, + 375, + 405, + 441, + 525, + 567, + 625, + 675, + 729, + 735, + 875, + 945, + 1029, + 1125, + 1215, + 1225, + 1323, + 1575, + 1701, + 1715, + 1875, + 2025, + 2187, + 2205, + 2401, + 2625, + 2835, + 3087, + 3125, + 3375, + 3645, + 3675, + 3969, + 4375, + 4725, + 5103, + 5145, + 5625, + 6075, + 6125, + 6561, + 6615, + 7203, + 7875, + 8505, + 8575, + 9261, + 9375, + 10125, + 10935, + 11025, + 11907, + 12005, + 13125, + 14175, + 15309, + 15435, + 15625, + 16807, + 16875, + 18225, + 18375, + 19683, + 19845, + 21609, + 21875, + 23625, + 25515, + 25725, + 27783, + 28125, + 30375, + 30625, + 32805, + 33075, + 35721, + 36015, + 39375, + 42525, + 42875, + 45927, + 46305, + 46875, + 50421, + 50625, + 54675, + 55125, + 59049, + 59535, + 60025, + 64827, + 65625, + 70875, + 76545, + 77175, + 78125, + 83349, + 84035, + 84375, + 91125, + 91875, + 98415, + 99225, + 107163, + 108045, + 109375, + 117649, + 118125, + 127575, + 128625, + 137781, + 138915, + 140625, + 151263, + 151875, + 153125, + 164025, + 165375, + 177147, + 178605, + 180075, + 194481, + 196875, + 212625, + 214375, + 229635, + 231525, + 234375, + 250047, + 252105, + 253125, + 273375, + 275625, + 295245, + 297675, + 300125, + 321489, + 324135, + 328125, + 352947, + 354375, + 382725, + 385875, + 390625, + 413343, + 416745, + 420175, + 421875, + 453789, + 455625, + 459375, + 492075, + 496125, + 531441, + 535815, + 540225, + 546875, + 583443, + 588245, + 590625, + 637875, + 643125, + 688905, + 694575, + 703125, + 750141, + 756315, + 759375, + 765625, + 820125, + 823543, + 826875, + 885735, + 893025, + 900375, + 964467, + 972405, + 984375, + 1058841, + 1063125, + 1071875, + 1148175, + 1157625, + 1171875, + 1240029, + 1250235, + 1260525, + 1265625, + 1361367, + 1366875, + 1378125, + 1476225, + 1488375, + 1500625, + 1594323, + 1607445, + 1620675, + 1640625, + 1750329, + 1764735, + 1771875, + 1913625, + 1929375, + 1953125, + 2066715, + 2083725, + 2100875, + 2109375, + 2250423, + 2268945, + 2278125, + 2296875, + 2460375, + 2470629, + 2480625, + 2657205, + 2679075, + 2701125, + 2734375, + 2893401, + 2917215, + 2941225, + 2953125, + 3176523, + 3189375, + 3215625, + 3444525, + 3472875, + 3515625, + 3720087, + 3750705, + 3781575, + 3796875, + 3828125, + 4084101, + 4100625, + 4117715, + 4134375, + 4428675, + 4465125, + 4501875, + 4782969, + 4822335, + 4862025, + 4921875, + 5250987, + 5294205, + 5315625, + 5359375, + 5740875, + 5764801, + 5788125, + 5859375, + 6200145, + 6251175, + 6302625, + 6328125, + 6751269, + 6806835, + 6834375, + 6890625, + 7381125, + 7411887, + 7441875, + 7503125, + 7971615, + 8037225, + 8103375, + 8203125, + 8680203, + 8751645, + 8823675, + 8859375, + 9529569, + 9568125, + 9646875, + 9765625, + 10333575, + 10418625, + 10504375, + 10546875, + 11160261, + 11252115, + 11344725, + 11390625, + 11484375, + 12252303, + 12301875, + 12353145, + 12403125, + 13286025, + 13395375, + 13505625, + 13671875, + 14348907, + 14467005, + 14586075, + 14706125, + 14765625, + 15752961, + 15882615, + 15946875, + 16078125, + 17222625, + 17294403, + 17364375, + 17578125, + 18600435, + 18753525, + 18907875, + 18984375, + 19140625, + 20253807, + 20420505, + 20503125, + 20588575, + 20671875, + 22143375, + 22235661, + 22325625, + 22509375, + 23914845, + 24111675, + 24310125, + 24609375, + 26040609, + 26254935, + 26471025, + 26578125, + 26796875, + 28588707, + 28704375, + 28824005, + 28940625, + 29296875, + 31000725, + 31255875, + 31513125, + 31640625, + 33480783, + 33756345, + 34034175, + 34171875, + 34453125, + 36756909, + 36905625, + 37059435, + 37209375, + 37515625, + 39858075, + 40186125, + 40353607, + 40516875, + 41015625, + 43046721, + 43401015, + 43758225, + 44118375, + 44296875, + 47258883, + 47647845, + 47840625, + 48234375, + 48828125, + 51667875, + 51883209, + 52093125, + 52521875, + 52734375, + 55801305, + 56260575, + 56723625, + 56953125, + 57421875, + 60761421, + 61261515, + 61509375, + 61765725, + 62015625, + 66430125, + 66706983, + 66976875, + 67528125, + 68359375, + 71744535, + 72335025, + 72930375, + 73530625, + 73828125, + 78121827, + 78764805, + 79413075, + 79734375, + 80390625, + 85766121, + 86113125, + 86472015, + 86821875, + 87890625, + 93002175, + 93767625, + 94539375, + 94921875, + 95703125, + 100442349, + 101269035, + 102102525, + 102515625, + 102942875, + 103359375, + 110270727, + 110716875, + 111178305, + 111628125, + 112546875, + 119574225, + 120558375, + 121060821, + 121550625, + 123046875, + 129140163, + 130203045, + 131274675, + 132355125, + 132890625, + 133984375, + 141776649, + 142943535, + 143521875, + 144120025, + 144703125, + 146484375, + 155003625, + 155649627, + 156279375, + 157565625, + 158203125, + 167403915, + 168781725, + 170170875, + 170859375, + 172265625, + 182284263, + 183784545, + 184528125, + 185297175, + 186046875, + 187578125, + 199290375, + 200120949, + 200930625, + 201768035, + 202584375, + 205078125, + 215233605, + 217005075, + 218791125, + 220591875, + 221484375, + 234365481, + 236294415, + 238239225, + 239203125, + 241171875, + 244140625, + 257298363, + 258339375, + 259416045, + 260465625, + 262609375, + 263671875, + 279006525, + 281302875, + 282475249, + 283618125, + 284765625, + 287109375, + 301327047, + 303807105, + 306307575, + 307546875, + 308828625, + 310078125, + 330812181, + 332150625, + 333534915, + 334884375, + 337640625, + 341796875, + 358722675, + 361675125, + 363182463, + 364651875, + 367653125, + 369140625, + 387420489, + 390609135, + 393824025, + 397065375, + 398671875, + 401953125, + 425329947, + 428830605, + 430565625, + 432360075, + 434109375, + 439453125, + 465010875, + 466948881, + 468838125, + 472696875, + 474609375, + 478515625, + 502211745, + 506345175, + 510512625, + 512578125, + 514714375, + 516796875, + 546852789, + 551353635, + 553584375, + 555891525, + 558140625, + 562734375, + 597871125, + 600362847, + 602791875, + 605304105, + 607753125, + 615234375, + 645700815, + 651015225, + 656373375, + 661775625, + 664453125, + 669921875, + 703096443, + 708883245, + 714717675, + 717609375, + 720600125, + 723515625, + 732421875, + 771895089, + 775018125, + 778248135, + 781396875, + 787828125, + 791015625, + 837019575, + 843908625, + 847425747, + 850854375, + 854296875, + 861328125, + 903981141, + 911421315, + 918922725, + 922640625, + 926485875, + 930234375, + 937890625, + 992436543, + 996451875, + 1000604745, + 1004653125, + 1008840175, + 1012921875, + 1025390625, + 1076168025, + 1085025375, + 1089547389, + 1093955625, + 1102959375, + 1107421875, + 1162261467, + 1171827405, + 1181472075, + 1191196125, + 1196015625, + 1205859375, + 1220703125, + 1275989841, + 1286491815, + 1291696875, + 1297080225, + 1302328125, + 1313046875, + 1318359375, + 1395032625, + 1400846643, + 1406514375, + 1412376245, + 1418090625, + 1423828125, + 1435546875, + 1506635235, + 1519035525, + 1531537875, + 1537734375, + 1544143125, + 1550390625, + 1640558367, + 1654060905, + 1660753125, + 1667674575, + 1674421875, + 1688203125, + 1708984375, + 1793613375, + 1801088541, + 1808375625, + 1815912315, + 1823259375, + 1838265625, + 1845703125, + 1937102445, + 1953045675, + 1969120125, + 1977326743, + 1985326875, + 1993359375, + 2009765625, + 2109289329, + 2126649735, + 2144153025, + 2152828125, ]; diff --git a/group-anagrams/index.ts b/group-anagrams/index.ts index b3d265a8..927749c4 100644 --- a/group-anagrams/index.ts +++ b/group-anagrams/index.ts @@ -2,7 +2,7 @@ import { groupBy } from "../deps.ts"; function groupAnagrams(strs: string[]) { return Object.values( - groupBy(strs, (str) => Array.from(str).sort().join("")) + groupBy(strs, (str) => Array.from(str).sort().join("")), ); } export default groupAnagrams; diff --git a/group-the-people-given-the-group-size-they-belong-to/index.ts b/group-the-people-given-the-group-size-they-belong-to/index.ts index 6d6a786b..fa8b6636 100644 --- a/group-the-people-given-the-group-size-they-belong-to/index.ts +++ b/group-the-people-given-the-group-size-they-belong-to/index.ts @@ -15,7 +15,7 @@ export default function groupThePeople(groupSizes: number[]): number[][] { ans.push( ...Array(Math.floor(people.length / size)) .fill(0) - .map((_, i) => people.slice(i, i + size)) + .map((_, i) => people.slice(i, i + size)), ); } return ans; diff --git a/grumpy-bookstore-owner/index.ts b/grumpy-bookstore-owner/index.ts index 0575476d..a9fdf386 100644 --- a/grumpy-bookstore-owner/index.ts +++ b/grumpy-bookstore-owner/index.ts @@ -1,7 +1,7 @@ export default function maxSatisfied( customers: number[], grumpy: number[], - minutes: number + minutes: number, ): number { let total = 0; const n = customers.length; @@ -16,8 +16,7 @@ export default function maxSatisfied( } let maxIncrease = increase; for (let i = minutes; i < n; i++) { - increase = - increase - + increase = increase - customers[i - minutes] * grumpy[i - minutes] + customers[i] * grumpy[i]; maxIncrease = Math.max(maxIncrease, increase); diff --git a/hPov7L/index.ts b/hPov7L/index.ts index 863b1e17..a03f51b1 100644 --- a/hPov7L/index.ts +++ b/hPov7L/index.ts @@ -19,6 +19,6 @@ function level(nodes: TreeNode[], output: (r: number) => void) { nodes .map((n) => [n.left, n.right].filter(Boolean) as TreeNode[]) .flat(), - output + output, ); } diff --git a/happy-number/index.ts b/happy-number/index.ts index c682bfaa..29bca032 100644 --- a/happy-number/index.ts +++ b/happy-number/index.ts @@ -15,14 +15,146 @@ function gethappynext(n: number) { } const smallerthan1000happy = new Set([ - 1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, - 100, 103, 109, 129, 130, 133, 139, 167, 176, 188, 190, 192, 193, 203, 208, - 219, 226, 230, 236, 239, 262, 263, 280, 291, 293, 301, 302, 310, 313, 319, - 320, 326, 329, 331, 338, 356, 362, 365, 367, 368, 376, 379, 383, 386, 391, - 392, 397, 404, 409, 440, 446, 464, 469, 478, 487, 490, 496, 536, 556, 563, - 565, 566, 608, 617, 622, 623, 632, 635, 637, 638, 644, 649, 653, 655, 656, - 665, 671, 673, 680, 683, 694, 700, 709, 716, 736, 739, 748, 761, 763, 784, - 790, 793, 802, 806, 818, 820, 833, 836, 847, 860, 863, 874, 881, 888, 899, - 901, 904, 907, 910, 912, 913, 921, 923, 931, 932, 937, 940, 946, 964, 970, - 973, 989, 998, + 1, + 7, + 10, + 13, + 19, + 23, + 28, + 31, + 32, + 44, + 49, + 68, + 70, + 79, + 82, + 86, + 91, + 94, + 97, + 100, + 103, + 109, + 129, + 130, + 133, + 139, + 167, + 176, + 188, + 190, + 192, + 193, + 203, + 208, + 219, + 226, + 230, + 236, + 239, + 262, + 263, + 280, + 291, + 293, + 301, + 302, + 310, + 313, + 319, + 320, + 326, + 329, + 331, + 338, + 356, + 362, + 365, + 367, + 368, + 376, + 379, + 383, + 386, + 391, + 392, + 397, + 404, + 409, + 440, + 446, + 464, + 469, + 478, + 487, + 490, + 496, + 536, + 556, + 563, + 565, + 566, + 608, + 617, + 622, + 623, + 632, + 635, + 637, + 638, + 644, + 649, + 653, + 655, + 656, + 665, + 671, + 673, + 680, + 683, + 694, + 700, + 709, + 716, + 736, + 739, + 748, + 761, + 763, + 784, + 790, + 793, + 802, + 806, + 818, + 820, + 833, + 836, + 847, + 860, + 863, + 874, + 881, + 888, + 899, + 901, + 904, + 907, + 910, + 912, + 913, + 921, + 923, + 931, + 932, + 937, + 940, + 946, + 964, + 970, + 973, + 989, + 998, ]); diff --git a/house-robber-ii/index.ts b/house-robber-ii/index.ts index ac609f4d..d579bfff 100644 --- a/house-robber-ii/index.ts +++ b/house-robber-ii/index.ts @@ -7,7 +7,7 @@ function rob(nums: number[]): number { } return Math.max( robRange(nums, 0, length - 2), - robRange(nums, 1, length - 1) + robRange(nums, 1, length - 1), ); } diff --git a/image-overlap/index.ts b/image-overlap/index.ts index f2d892aa..47ae206f 100644 --- a/image-overlap/index.ts +++ b/image-overlap/index.ts @@ -1,6 +1,6 @@ export default function largestOverlap( img1: number[][], - img2: number[][] + img2: number[][], ): number { const len = img1.length; const count: number[][] = Array(2 * len + 1) diff --git a/implement-rand10-using-rand7/index.ts b/implement-rand10-using-rand7/index.ts index f4b03975..c3a9defd 100644 --- a/implement-rand10-using-rand7/index.ts +++ b/implement-rand10-using-rand7/index.ts @@ -1,8 +1,7 @@ import { rand7 } from "./rand7.ts"; export default function rand10(): number { - const a = - rand7() - + const a = rand7() - 1 + 7 * (rand7() - 1) + (rand7() - 1) * 7 * 7 + diff --git a/insert-into-a-binary-search-tree/index.ts b/insert-into-a-binary-search-tree/index.ts index a765a617..ef39b23d 100644 --- a/insert-into-a-binary-search-tree/index.ts +++ b/insert-into-a-binary-search-tree/index.ts @@ -2,7 +2,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function insertIntoBST( root: TreeNode | null, - val: number + val: number, ): TreeNode | null { if (root === null) return { val, left: null, right: null }; if (root.val > val) root.left = insertIntoBST(root.left, val); diff --git a/integer-replacement/index.ts b/integer-replacement/index.ts index 2f04d260..6cf247bf 100644 --- a/integer-replacement/index.ts +++ b/integer-replacement/index.ts @@ -2,9 +2,7 @@ function integerReplacement(n: number): number { return n === 1 ? 0 : n % 2 === 0 - ? Math.log2(n) % 1 === 0 - ? Math.log2(n) - : integerReplacement(n / 2) + 1 + ? Math.log2(n) % 1 === 0 ? Math.log2(n) : integerReplacement(n / 2) + 1 : Math.min(integerReplacement(n + 1), integerReplacement(n - 1)) + 1; } export default integerReplacement; diff --git a/intersection-of-two-arrays/index.ts b/intersection-of-two-arrays/index.ts index 7da6af13..6e3ae43b 100644 --- a/intersection-of-two-arrays/index.ts +++ b/intersection-of-two-arrays/index.ts @@ -1,6 +1,6 @@ export default function intersection( nums1: number[], - nums2: number[] + nums2: number[], ): number[] { const set = new Set(nums2); return Array.from(new Set(nums1.filter((a) => set.has(a)))); diff --git a/intersection-of-two-linked-lists/index.ts b/intersection-of-two-linked-lists/index.ts index 7423f331..76ff61fa 100644 --- a/intersection-of-two-linked-lists/index.ts +++ b/intersection-of-two-linked-lists/index.ts @@ -2,7 +2,7 @@ import { ListNode } from "../reverse-linked-list/ListNode.ts"; export default function getIntersectionNode( headA: ListNode | null, - headB: ListNode | null + headB: ListNode | null, ): ListNode | null { if (!headA) return null; if (!headB) return null; diff --git a/interval-list-intersections/index.ts b/interval-list-intersections/index.ts index c80990c0..4bca0514 100644 --- a/interval-list-intersections/index.ts +++ b/interval-list-intersections/index.ts @@ -1,6 +1,6 @@ export default function intervalIntersection( firstList: number[][], - secondList: number[][] + secondList: number[][], ): number[][] { const events: [number, number][] = []; for (let i = 0; i < firstList.length; i++) { diff --git a/is-graph-bipartite/index.ts b/is-graph-bipartite/index.ts index 4faa5ef0..be58486c 100644 --- a/is-graph-bipartite/index.ts +++ b/is-graph-bipartite/index.ts @@ -8,8 +8,9 @@ export default function isBipartite(graph: number[][]): boolean { while (queue.length) { const temp: number[] = []; for (const node of queue) { - const neighbor_color = - color[node] === Colors.One ? Colors.Two : Colors.One; + const neighbor_color = color[node] === Colors.One + ? Colors.Two + : Colors.One; for (const neighbor of graph[node]) { if (color[neighbor] === Colors.None) { diff --git a/jewels-and-stones/index.ts b/jewels-and-stones/index.ts index 1ea827a8..382d612a 100644 --- a/jewels-and-stones/index.ts +++ b/jewels-and-stones/index.ts @@ -1,6 +1,6 @@ export default function numJewelsInStones( jewels: string, - stones: string + stones: string, ): number { const set = new Set(jewels); @@ -11,6 +11,6 @@ export default function numJewelsInStones( // deno-lint-ignore ban-ts-comment //@ts-ignore (a, v) => a + Number(set.has(v)), - 0 + 0, ); } diff --git a/k-similar-strings/index.ts b/k-similar-strings/index.ts index 377b8835..bf800ab5 100644 --- a/k-similar-strings/index.ts +++ b/k-similar-strings/index.ts @@ -17,7 +17,7 @@ export default function kSimilarity(s1: string, s2: string): number { cost: number, len: number, str1: string | string[], - str2: string + str2: string, ) { if (cost > ans) { return; diff --git a/kids-with-the-greatest-number-of-candies/index.ts b/kids-with-the-greatest-number-of-candies/index.ts index 6430d9e9..01986ce6 100644 --- a/kids-with-the-greatest-number-of-candies/index.ts +++ b/kids-with-the-greatest-number-of-candies/index.ts @@ -1,6 +1,6 @@ export default function kidsWithCandies( candies: number[], - extraCandies: number + extraCandies: number, ): boolean[] { const max = Math.max(...candies); return candies.map((candy) => candy + extraCandies >= max); diff --git a/largest-local-values-in-a-matrix/index.ts b/largest-local-values-in-a-matrix/index.ts index dda32fb6..448f2413 100644 --- a/largest-local-values-in-a-matrix/index.ts +++ b/largest-local-values-in-a-matrix/index.ts @@ -23,7 +23,7 @@ export default function largestLocal(grid: number[][]): number[][] { .map((_, j) => { return Math.max( grid[i + 1][j + 1], - ...dirs.map(([r, c]) => grid[i + 1 + r]?.[j + 1 + c]) + ...dirs.map(([r, c]) => grid[i + 1 + r]?.[j + 1 + c]), ); }) ); diff --git a/largest-number/index.ts b/largest-number/index.ts index c0ac17ef..9653b259 100644 --- a/largest-number/index.ts +++ b/largest-number/index.ts @@ -2,7 +2,7 @@ export default function largestNumber(nums: number[]): string { return nums .sort( (a, b) => - -Number(String(a) + String(b)) + Number(String(b) + String(a)) + -Number(String(a) + String(b)) + Number(String(b) + String(a)), ) .join("") .replace(/^0+/g, "0"); diff --git a/largest-plus-sign/index.ts b/largest-plus-sign/index.ts index c4cd9279..3feb6d89 100644 --- a/largest-plus-sign/index.ts +++ b/largest-plus-sign/index.ts @@ -1,6 +1,6 @@ export default function orderOfLargestPlusSign( n: number, - mines: number[][] + mines: number[][], ): number { const dp: number[][] = Array(n) .fill(0) diff --git a/largest-sum-of-averages/index.ts b/largest-sum-of-averages/index.ts index ddcdb84f..3eb945af 100644 --- a/largest-sum-of-averages/index.ts +++ b/largest-sum-of-averages/index.ts @@ -17,12 +17,12 @@ function largestSumOfAverages(nums: number[], k: number): number { for (let i = k - 1; i < n; i++) { ans = Math.max( ans, - dfs(i, k - 1) + (presum[n] - presum[i]) / (n - i) + dfs(i, k - 1) + (presum[n] - presum[i]) / (n - i), ); } return ans; }, - (n: number, k: number): string => JSON.stringify([n, k]) + (n: number, k: number): string => JSON.stringify([n, k]), ); return dfs(n, k); } diff --git a/largest-triangle-area/index.ts b/largest-triangle-area/index.ts index 84d42f85..95eccc1d 100644 --- a/largest-triangle-area/index.ts +++ b/largest-triangle-area/index.ts @@ -9,7 +9,7 @@ export default function largestTriangleArea(points: number[][]): number { number, number, number, - number + number, ]; const area = triangleArea(...pos); ret = Math.max(ret, area); @@ -23,7 +23,7 @@ function triangleArea( x2: number, y2: number, x3: number, - y3: number + y3: number, ) { return ( 0.5 * diff --git a/letter-combinations-of-a-phone-number/index.ts b/letter-combinations-of-a-phone-number/index.ts index 99a14f2b..76280ad3 100644 --- a/letter-combinations-of-a-phone-number/index.ts +++ b/letter-combinations-of-a-phone-number/index.ts @@ -16,18 +16,17 @@ export default function letterCombinations(digits: string): string[] { ( //@ts-ignore p, - c //@ts-ignore - ) => - p - .map( - (v) => - //@ts-ignore - KEY_MAP[c] //@ts-ignore - .map((q) => /*@ts-ignore*/ v + q) //@ts-ignore - .flat(Infinity) as string[] //@ts-ignore - ) //@ts-ignore - .flat(Infinity) as string[], - [""] //@ts-ignore + c, //@ts-ignore + ) => p + .map( + (v) => + //@ts-ignore + KEY_MAP[c] //@ts-ignore + .map((q) => /*@ts-ignore*/ v + q) //@ts-ignore + .flat(Infinity) as string[], //@ts-ignore + ) //@ts-ignore + .flat(Infinity) as string[], + [""], //@ts-ignore ) //@ts-ignore .flat(Infinity) as string[]; } diff --git a/lfu-cache/index.ts b/lfu-cache/index.ts index cad05359..752fec67 100644 --- a/lfu-cache/index.ts +++ b/lfu-cache/index.ts @@ -97,8 +97,8 @@ class LFUCache { // debugger; if (!this.#has(key)) { if (this.#size === this.#capacity) { - const to_be_removed_key = - this.#least_frequently_recently_used_key(); + const to_be_removed_key = this + .#least_frequently_recently_used_key(); if (typeof to_be_removed_key === "number") { this.#delete(to_be_removed_key); } diff --git a/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/index.ts b/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/index.ts index fb255401..ee20797f 100644 --- a/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/index.ts +++ b/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/index.ts @@ -1,6 +1,6 @@ export default function getKthFromEnd( head: ListNode | null, - k: number + k: number, ): ListNode | null { if (!head) return head; if (!head.next) return head; diff --git a/license-key-formatting/index.ts b/license-key-formatting/index.ts index 0cd2805b..26eb3414 100644 --- a/license-key-formatting/index.ts +++ b/license-key-formatting/index.ts @@ -11,9 +11,9 @@ export default function licenseKeyFormatting(s: string, k: number): string { : str.slice(i * k, i * k + k) : str.length % k ? str.slice( - -k + (str.length % k) + i * k, - -k + (str.length % k) + i * k + k - ) + -k + (str.length % k) + i * k, + -k + (str.length % k) + i * k + k, + ) : str.slice(i * k, i * k + k) ) .join("-"); diff --git a/linked-list-components/index.ts b/linked-list-components/index.ts index 4ea1c28c..d97df062 100644 --- a/linked-list-components/index.ts +++ b/linked-list-components/index.ts @@ -2,7 +2,7 @@ import { ListNode } from "../reverse-linked-list/ListNode.ts"; export default function numComponents( head: ListNode | null, - nums: number[] + nums: number[], ): number { const numsSet = new Set(); for (const num of nums) { diff --git a/linked-list-in-binary-tree/index.ts b/linked-list-in-binary-tree/index.ts index e5f167ec..70fb93a1 100644 --- a/linked-list-in-binary-tree/index.ts +++ b/linked-list-in-binary-tree/index.ts @@ -16,7 +16,7 @@ function dfs(rt: TreeNode | null, head: ListNode | null): boolean { export default function isSubPath( head: ListNode | null, - root: TreeNode | null + root: TreeNode | null, ): boolean { if (root == null) return !!0; return ( diff --git a/long-pressed-name/index.ts b/long-pressed-name/index.ts index 6b5dca6a..c5c4f73d 100644 --- a/long-pressed-name/index.ts +++ b/long-pressed-name/index.ts @@ -1,12 +1,12 @@ export default function isLongPressedName( name: string, - typed: string + typed: string, ): boolean { return ( name === typed || new RegExp( "^" + Array.prototype.map.call(name, (c) => c + "+").join("") + "$", - "g" + "g", ).test(typed) ); } diff --git a/longest-absolute-file-path/index.ts b/longest-absolute-file-path/index.ts index 57d0ab28..bfa2ef79 100644 --- a/longest-absolute-file-path/index.ts +++ b/longest-absolute-file-path/index.ts @@ -15,13 +15,13 @@ export default function lengthLongestPath(input: string): number { if (line.includes(".")) { folder_current.length = count_char(line, "\t"); files_path.add( - [...folder_current, line.replaceAll("\t", "")].join("/") + [...folder_current, line.replaceAll("\t", "")].join("/"), ); } else { folder_current.length = 1 + count_char(line, "\t"); folder_current[folder_current.length - 1] = line.replaceAll( "\t", - "" + "", ); } } diff --git a/longest-uncommon-subsequence-ii/index.ts b/longest-uncommon-subsequence-ii/index.ts index 00b2f985..892d1f4d 100644 --- a/longest-uncommon-subsequence-ii/index.ts +++ b/longest-uncommon-subsequence-ii/index.ts @@ -13,7 +13,7 @@ export default function findLUSlength(strs: string[]): number { return check; }) - .map((str) => str.length) + .map((str) => str.length), ); } diff --git a/lowest-common-ancestor-of-a-binary-tree/index.ts b/lowest-common-ancestor-of-a-binary-tree/index.ts index caa94dd0..1c3bb425 100644 --- a/lowest-common-ancestor-of-a-binary-tree/index.ts +++ b/lowest-common-ancestor-of-a-binary-tree/index.ts @@ -3,7 +3,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; function lowestCommonAncestor( root?: TreeNode | null, p?: TreeNode | null, - q?: TreeNode | null + q?: TreeNode | null, ): TreeNode | null { if (!root) return null; const visited = new WeakSet(); diff --git a/make-two-arrays-equal-by-reversing-sub-arrays/index.ts b/make-two-arrays-equal-by-reversing-sub-arrays/index.ts index 10de31f3..ae2b2ed0 100644 --- a/make-two-arrays-equal-by-reversing-sub-arrays/index.ts +++ b/make-two-arrays-equal-by-reversing-sub-arrays/index.ts @@ -9,7 +9,7 @@ function MapisEqual(a: Map, b: Map) { a === b || (a.size === b.size && Array.from(a.keys()).every( - (k) => b.has(k) && a.get(k) === b.get(k) + (k) => b.has(k) && a.get(k) === b.get(k), )) ); } diff --git a/making-a-large-island/index.ts b/making-a-large-island/index.ts index 7c988634..38c916ba 100644 --- a/making-a-large-island/index.ts +++ b/making-a-large-island/index.ts @@ -49,9 +49,9 @@ export default function largestIsland(grid: number[][]): number { ]; const uniqed = uniqBy( neighbours.filter( - ([x, y]) => is_valid_position(x, y) && grid[x][y] === 1 + ([x, y]) => is_valid_position(x, y) && grid[x][y] === 1, ), - ([x, y]) => get_island_id_of_position(x, y) + ([x, y]) => get_island_id_of_position(x, y), ); for (const [x, y] of uniqed) { //还要判断是否是相连的岛屿 @@ -101,7 +101,7 @@ function dfs( r: number, c: number, cache: Set, - output: (p: [number, number]) => void + output: (p: [number, number]) => void, ): void { const m = grid.length; if (m === 0) { diff --git a/matchsticks-to-square/index.ts b/matchsticks-to-square/index.ts index 9df0c0e6..14ae7d5e 100644 --- a/matchsticks-to-square/index.ts +++ b/matchsticks-to-square/index.ts @@ -16,7 +16,7 @@ const dfs = ( index: number, matchsticks: number[], edges: number[], - len: number + len: number, ) => { if (index === matchsticks.length) { return true; diff --git a/matrix-diagonal-sum/index.ts b/matrix-diagonal-sum/index.ts index 00a6abf7..ff3e83c4 100644 --- a/matrix-diagonal-sum/index.ts +++ b/matrix-diagonal-sum/index.ts @@ -4,6 +4,6 @@ export default function diagonalSum(e: number[][]) { r === t.length - r - 1 ? e + t[r][r] : e + t[r][r] + t[r][t.length - r - 1], - 0 + 0, ); } diff --git a/max-area-of-island/index.ts b/max-area-of-island/index.ts index ecea55c2..bc21aaf9 100644 --- a/max-area-of-island/index.ts +++ b/max-area-of-island/index.ts @@ -37,7 +37,7 @@ function dfs( r: number, c: number, cache: Set, - output: () => void + output: () => void, ): void { const m = grid.length; if (m === 0) return; diff --git a/maximize-score-after-n-operations/index.ts b/maximize-score-after-n-operations/index.ts index baac4788..50964f20 100644 --- a/maximize-score-after-n-operations/index.ts +++ b/maximize-score-after-n-operations/index.ts @@ -23,7 +23,7 @@ function maxScore(nums: number[]): number { dp[s] = Math.max( dp[s], dp[s ^ (1 << i) ^ (1 << j)] + - Math.floor(t / 2) * gcdTmp[i][j] + Math.floor(t / 2) * gcdTmp[i][j], ); } } diff --git a/maximize-the-confusion-of-an-exam/index.ts b/maximize-the-confusion-of-an-exam/index.ts index 8b863a34..27f87b73 100644 --- a/maximize-the-confusion-of-an-exam/index.ts +++ b/maximize-the-confusion-of-an-exam/index.ts @@ -1,6 +1,6 @@ export default function maxConsecutiveAnswers( answerKey: string, - k: number + k: number, ): number { let countF = 0; // 当前窗口内F的数量 let countT = 0; // 当前窗口内T的数量 diff --git a/maximum-and-sum-of-array/index.ts b/maximum-and-sum-of-array/index.ts index 4a0a8fd7..df44e0f8 100644 --- a/maximum-and-sum-of-array/index.ts +++ b/maximum-and-sum-of-array/index.ts @@ -24,7 +24,7 @@ function maximumANDSum(nums: number[], numSlots: number): number { if (filled(state, j) >= 1) { dp[i][state] = max( dp[i][state], - dp[i - 1][state - pow(3, j)] + (nums[i] & (j + 1)) + dp[i - 1][state - pow(3, j)] + (nums[i] & (j + 1)), ); } } diff --git a/maximum-binary-tree-ii/index.ts b/maximum-binary-tree-ii/index.ts index 2c8ed6f7..d9dd8446 100644 --- a/maximum-binary-tree-ii/index.ts +++ b/maximum-binary-tree-ii/index.ts @@ -2,7 +2,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function insertIntoMaxTree( root: TreeNode | null, - val: number + val: number, ): TreeNode | null { // 如果root是空节点的话,就以val返回一个新节点 // 如果 val 是整棵树最大的,那么原来的这棵树应该是 val 节点的左子树,因为 val 节点是接在原始数组 a 的最后一个元素 diff --git a/maximum-binary-tree/index.ts b/maximum-binary-tree/index.ts index 623a9bcd..fdafef87 100644 --- a/maximum-binary-tree/index.ts +++ b/maximum-binary-tree/index.ts @@ -2,10 +2,10 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; import insertIntoMaxTree from "../maximum-binary-tree-ii/index.ts"; export default function constructMaximumBinaryTree( - nums: number[] + nums: number[], ): TreeNode | null { return nums.reduce( (a: TreeNode | null, v: number) => insertIntoMaxTree(a, v), - null + null, ); } diff --git a/maximum-equal-frequency/index.ts b/maximum-equal-frequency/index.ts index a8e85b1f..8b2502e9 100644 --- a/maximum-equal-frequency/index.ts +++ b/maximum-equal-frequency/index.ts @@ -14,11 +14,10 @@ export default function maxEqualFreq(nums: number[]) { freq.set(curCount, (freq.get(count.get(nums[i]) ?? 0) ?? 0) + 1); const maxFreqCount = freq.get(maxFreq) ?? 0; - const ok = - maxFreq === 1 || + const ok = maxFreq === 1 || (maxFreqCount * maxFreq + - (freq.get(maxFreq - 1) ?? 0) * (maxFreq - 1) === - i + 1 && + (freq.get(maxFreq - 1) ?? 0) * (maxFreq - 1) === + i + 1 && maxFreqCount === 1) || (maxFreqCount * maxFreq + 1 === i + 1 && freq.get(1) === 1); if (ok) { diff --git a/maximum-matching-of-players-with-trainers/index.ts b/maximum-matching-of-players-with-trainers/index.ts index 435d2429..3a364d8b 100644 --- a/maximum-matching-of-players-with-trainers/index.ts +++ b/maximum-matching-of-players-with-trainers/index.ts @@ -1,6 +1,6 @@ export default function matchPlayersAndTrainers( players: number[], - trainers: number[] + trainers: number[], ): number { players.sort((a, b) => a - b); trainers.sort((a, b) => a - b); diff --git a/maximum-number-of-balloons/index.ts b/maximum-number-of-balloons/index.ts index 4853da27..e5168036 100644 --- a/maximum-number-of-balloons/index.ts +++ b/maximum-number-of-balloons/index.ts @@ -6,7 +6,7 @@ function maxNumberOfBalloons(text: string): number { return Math.min( ...Array.from(bat.entries()).map(([s, c]) => Math.floor((cnt.get(s) ?? 0) / c) - ) + ), ); } diff --git a/maximum-number-of-balls-in-a-box/index.ts b/maximum-number-of-balls-in-a-box/index.ts index 2f86e85b..0e9a5a3c 100644 --- a/maximum-number-of-balls-in-a-box/index.ts +++ b/maximum-number-of-balls-in-a-box/index.ts @@ -1,6 +1,6 @@ export default function countBalls( lowLimit: number, - highLimit: number + highLimit: number, ): number { const cnt = new Map(); for (let index = lowLimit; index <= highLimit; index++) { diff --git a/maximum-number-of-words-found-in-sentences/index.ts b/maximum-number-of-words-found-in-sentences/index.ts index ea0cd500..e4c877ce 100644 --- a/maximum-number-of-words-found-in-sentences/index.ts +++ b/maximum-number-of-words-found-in-sentences/index.ts @@ -6,6 +6,6 @@ export default function mostWordsFound(sentences: string[]): number { // deno-lint-ignore ban-ts-comment //@ts-ignore Array.prototype.reduce.call(s, (a, v) => a + Number(v === " "), 1) - ) + ), ); } diff --git a/maximum-product-of-splitted-binary-tree/index.ts b/maximum-product-of-splitted-binary-tree/index.ts index c2baf003..16bd5bf1 100644 --- a/maximum-product-of-splitted-binary-tree/index.ts +++ b/maximum-product-of-splitted-binary-tree/index.ts @@ -11,7 +11,7 @@ export default function maxProduct(root: TreeNode | null): number { function maxTree(root: TreeNode | null, output?: (a: number) => void): number { if (!root) return output?.(0), 0; - const all = - maxTree(root.left, output) + maxTree(root.right, output) + root.val; + const all = maxTree(root.left, output) + maxTree(root.right, output) + + root.val; return output?.(all), all; } diff --git a/maximum-product-of-two-elements-in-an-array/index.ts b/maximum-product-of-two-elements-in-an-array/index.ts index 8b3b67a7..30318f5e 100644 --- a/maximum-product-of-two-elements-in-an-array/index.ts +++ b/maximum-product-of-two-elements-in-an-array/index.ts @@ -1,13 +1,13 @@ export default function maxProduct(nums: number[]): number { const max_pair = nums.reduce( (a, v, i): [number, number] => (v > a[1] ? [i, v] : a), - [0, nums[0]] as [number, number] + [0, nums[0]] as [number, number], ); nums.splice(max_pair[0], 1); const sec_max_pair = nums.reduce( (a, v, i): [number, number] => (v > a[1] ? [i, v] : a), - [0, nums[0]] as [number, number] + [0, nums[0]] as [number, number], ); return (sec_max_pair[1] - 1) * (max_pair[1] - 1); diff --git a/maximum-profit-in-job-scheduling/index.ts b/maximum-profit-in-job-scheduling/index.ts index 4fc2aef6..93ec930c 100644 --- a/maximum-profit-in-job-scheduling/index.ts +++ b/maximum-profit-in-job-scheduling/index.ts @@ -3,7 +3,7 @@ import { upperBound } from "./upperBound.ts"; function jobScheduling( startTime: number[], endTime: number[], - profit: number[] + profit: number[], ): number { const jobs = startTime .map((v, i) => [v, endTime[i], profit[i]]) diff --git a/maximum-rows-covered-by-columns/index.ts b/maximum-rows-covered-by-columns/index.ts index 64689e58..5227808a 100644 --- a/maximum-rows-covered-by-columns/index.ts +++ b/maximum-rows-covered-by-columns/index.ts @@ -1,6 +1,6 @@ export default function maximumRows( mat: number[][], - numSelect: number + numSelect: number, ): number { const n = mat[0].length; //const m = mat.length diff --git a/maximum-score-after-splitting-a-string/index.ts b/maximum-score-after-splitting-a-string/index.ts index 0d0dec65..3718e401 100644 --- a/maximum-score-after-splitting-a-string/index.ts +++ b/maximum-score-after-splitting-a-string/index.ts @@ -12,6 +12,6 @@ export default function maxScore(s: string): number { return Math.max( ...Array(s.length - 1) .fill(0) - .map((_, i) => prefixSum[i + 1] + suffixSum[i + 1]) + .map((_, i) => prefixSum[i + 1] + suffixSum[i + 1]), ); } diff --git a/maximum-units-on-a-truck/index.ts b/maximum-units-on-a-truck/index.ts index c1255178..c6f07ab0 100644 --- a/maximum-units-on-a-truck/index.ts +++ b/maximum-units-on-a-truck/index.ts @@ -1,6 +1,6 @@ export default function maximumUnits( boxTypes: number[][], - truckSize: number + truckSize: number, ): number { boxTypes.sort((a, b) => b[1] - a[1]); let res = 0; diff --git a/maximum-value-at-a-given-index-in-a-bounded-array/index.ts b/maximum-value-at-a-given-index-in-a-bounded-array/index.ts index c0ad82bd..336534d1 100644 --- a/maximum-value-at-a-given-index-in-a-bounded-array/index.ts +++ b/maximum-value-at-a-given-index-in-a-bounded-array/index.ts @@ -7,8 +7,7 @@ function maxValue(n: number, index: number, maxSum: number): number { right = temp; } - let upper = - ((left + 1) * (left + 1) - 3 * (left + 1)) / 2 + + let upper = ((left + 1) * (left + 1) - 3 * (left + 1)) / 2 + left + 1 + (left + 1) + @@ -22,8 +21,7 @@ function maxValue(n: number, index: number, maxSum: number): number { return Math.floor((-b + Math.sqrt(b * b - 4 * a * c)) / (2 * a)); } - upper = - ((2 * (right + 1) - left - 1) * left) / 2 + + upper = ((2 * (right + 1) - left - 1) * left) / 2 + (right + 1) + ((right + 1) * (right + 1) - 3 * (right + 1)) / 2 + right + diff --git a/maximum-value-of-a-string-in-an-array/index.ts b/maximum-value-of-a-string-in-an-array/index.ts index 117e909c..55faec86 100644 --- a/maximum-value-of-a-string-in-an-array/index.ts +++ b/maximum-value-of-a-string-in-an-array/index.ts @@ -1,7 +1,7 @@ function maximumValue(strs: string[]): number { return strs.reduce( (p, c) => Math.max(p, /^\d+$/.test(c) ? Number(c) : c.length), - 0 + 0, ); } export default maximumValue; diff --git a/maximum-width-of-binary-tree/index.ts b/maximum-width-of-binary-tree/index.ts index ecec549d..288069b0 100644 --- a/maximum-width-of-binary-tree/index.ts +++ b/maximum-width-of-binary-tree/index.ts @@ -29,8 +29,8 @@ export default function widthOfBinaryTree(root: TreeNode | null): number { Number( 1n + bigintMax(...latest.keys()) - - bigintMin(...latest.keys()) - ) + bigintMin(...latest.keys()), + ), ); } else break; } diff --git a/median-of-two-sorted-arrays/index.ts b/median-of-two-sorted-arrays/index.ts index bd876d5b..3b73e4fa 100644 --- a/median-of-two-sorted-arrays/index.ts +++ b/median-of-two-sorted-arrays/index.ts @@ -1,6 +1,6 @@ export default function findMedianSortedArrays( nums1: number[], - nums2: number[] + nums2: number[], ): number { const arr = [...nums1, ...nums2].sort((a, b) => a - b); if (arr.length % 2) { diff --git a/merge-in-between-linked-lists/index.ts b/merge-in-between-linked-lists/index.ts index ea0cc958..3a459422 100644 --- a/merge-in-between-linked-lists/index.ts +++ b/merge-in-between-linked-lists/index.ts @@ -6,7 +6,7 @@ export default function mergeInBetween( list1: ListNode | null, a: number, b: number, - list2: ListNode | null + list2: ListNode | null, ): ListNode | null { if (!list1) { return list1; diff --git a/merge-intervals/index.ts b/merge-intervals/index.ts index 0bf581df..b68e5645 100644 --- a/merge-intervals/index.ts +++ b/merge-intervals/index.ts @@ -11,7 +11,7 @@ export default function merge(intervals: number[][]): number[][] { } else { merged[merged.length - 1][1] = Math.max( merged[merged.length - 1][1], - interval[1] + interval[1], ); } } diff --git a/merge-sorted-array/index.ts b/merge-sorted-array/index.ts index d1a3fc4b..1fb23729 100644 --- a/merge-sorted-array/index.ts +++ b/merge-sorted-array/index.ts @@ -2,7 +2,7 @@ export default function merge( nums1: number[], m: number, nums2: number[], - n: number + n: number, ): void { if (n === 0) { return; diff --git a/merge-two-binary-trees/index.ts b/merge-two-binary-trees/index.ts index e23a1915..3042a085 100644 --- a/merge-two-binary-trees/index.ts +++ b/merge-two-binary-trees/index.ts @@ -2,7 +2,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; function mergeTrees( root1: TreeNode | null, - root2: TreeNode | null + root2: TreeNode | null, ): TreeNode | null { if (!root1 && !root2) return null; if (!root1) return root2; diff --git a/merge-two-sorted-lists/index.ts b/merge-two-sorted-lists/index.ts index c4bb196e..8c61a294 100644 --- a/merge-two-sorted-lists/index.ts +++ b/merge-two-sorted-lists/index.ts @@ -2,7 +2,7 @@ import { ListNode } from "../reverse-linked-list/ListNode.ts"; export default function mergeTwoLists( list1: ListNode | null, - list2: ListNode | null + list2: ListNode | null, ): ListNode | null { if (!list1) return list2; if (!list2) return list1; diff --git a/min-cost-to-connect-all-points/index.ts b/min-cost-to-connect-all-points/index.ts index 24bc7c50..29513789 100644 --- a/min-cost-to-connect-all-points/index.ts +++ b/min-cost-to-connect-all-points/index.ts @@ -2,7 +2,7 @@ function minCostConnectPoints(points: number[][]): number { const p0 = points[0]; const ds: Map = new Map( - points.map((p, i) => [i, 曼哈顿距离(p, p0)]) + points.map((p, i) => [i, 曼哈顿距离(p, p0)]), ); ds.delete(0); let ans = 0; diff --git a/minesweeper/index.ts b/minesweeper/index.ts index 3ccbfb62..a2000245 100644 --- a/minesweeper/index.ts +++ b/minesweeper/index.ts @@ -1,6 +1,6 @@ export default function updateBoard( board: string[][], - click: number[] + click: number[], ): string[][] { const [row, col] = click; if (board[row][col] === "M") { @@ -13,14 +13,14 @@ export default function updateBoard( .filter((v) => typeof board[v[0]]?.[v[1]] !== "undefined"); const count = validpos.reduce( (a, v) => a + Number(["X", "M"].includes(board[v[0]][v[1]])), - 0 + 0, ); if (count > 0) board[row][col] = String(count); else { board[row][col] = "B"; return validpos.reduce( (b, v) => updateBoard(b, [v[0], v[1]]), - board + board, ); } return board; diff --git a/mini-parser/index.ts b/mini-parser/index.ts index 420daace..5c3b3061 100644 --- a/mini-parser/index.ts +++ b/mini-parser/index.ts @@ -48,7 +48,7 @@ export default function deserialize(s: string): NestedInteger { const nums = new Set( Array.from({ length: 10, - }).map((_v, i) => String(i)) + }).map((_v, i) => String(i)), ); function isDigit(ch: string) { return nums.has(ch); diff --git a/minimum-absolute-difference-in-bst/index.ts b/minimum-absolute-difference-in-bst/index.ts index 5d4e78d6..7b46c43f 100644 --- a/minimum-absolute-difference-in-bst/index.ts +++ b/minimum-absolute-difference-in-bst/index.ts @@ -5,6 +5,6 @@ export default function getMinimumDifference(root: TreeNode | null): number { const nums = inorderTraversal(root); return Math.min( - ...nums.map((v, i, a) => Math.abs((a[i + 1] ?? Infinity) - v)) + ...nums.map((v, i, a) => Math.abs((a[i + 1] ?? Infinity) - v)), ); } diff --git a/minimum-absolute-difference-queries/index.ts b/minimum-absolute-difference-queries/index.ts index dff69fc0..ee5d227c 100644 --- a/minimum-absolute-difference-queries/index.ts +++ b/minimum-absolute-difference-queries/index.ts @@ -1,6 +1,6 @@ export default function minDifference( nums: number[], - queries: number[][] + queries: number[][], ): number[] { const n = nums.length; const sorted = [...new Set(nums)].sort((a, b) => a - b); @@ -9,16 +9,15 @@ export default function minDifference( for (const k of sorted) { presum[k - 1] = Array(n).fill(0); for (let i = 0; i < n; i++) { - presum[k - 1][i] = - (i == 0 ? 0 : presum[k - 1][i - 1]) + Number(nums[i] == k); + presum[k - 1][i] = (i == 0 ? 0 : presum[k - 1][i - 1]) + + Number(nums[i] == k); } } return queries.map(([left, right]) => { const arr = Array(); for (const k of sorted) { - const count = - presum[k - 1][right] - + const count = presum[k - 1][right] - (left == 0 ? 0 : presum[k - 1][left - 1]); if (count) { @@ -35,7 +34,7 @@ export default function minDifference( if (arr.length <= 1) return -1; else { return Math.min( - ...arr.map((v, i, a) => (i === 0 ? Infinity : v - a[i - 1])) + ...arr.map((v, i, a) => (i === 0 ? Infinity : v - a[i - 1])), ); } }); diff --git a/minimum-absolute-difference/index.ts b/minimum-absolute-difference/index.ts index b41ecbf8..8e358ba3 100644 --- a/minimum-absolute-difference/index.ts +++ b/minimum-absolute-difference/index.ts @@ -11,7 +11,7 @@ function minimumAbsDifference(arr: number[]): number[][] { } return [res, num]; }, - [[], Infinity] as [number[][], number] + [[], Infinity] as [number[][], number], )[0]; } export default minimumAbsDifference; diff --git a/minimum-addition-to-make-integer-beautiful/index.ts b/minimum-addition-to-make-integer-beautiful/index.ts index 2e7dfcbd..d3a1eb08 100644 --- a/minimum-addition-to-make-integer-beautiful/index.ts +++ b/minimum-addition-to-make-integer-beautiful/index.ts @@ -1,6 +1,6 @@ export default function makeIntegerBeautiful( n: number, - target: number + target: number, ): number { // 分隔n为数字数组 const nArr = n.toString().split("").map(Number); diff --git a/minimum-adjacent-swaps-for-k-consecutive-ones/index.ts b/minimum-adjacent-swaps-for-k-consecutive-ones/index.ts index 43a4a2e4..02a5d400 100644 --- a/minimum-adjacent-swaps-for-k-consecutive-ones/index.ts +++ b/minimum-adjacent-swaps-for-k-consecutive-ones/index.ts @@ -17,7 +17,7 @@ function minMoves(nums: number[], k: number): number { res, (1 - (k % 2)) * r + (preSum[i + k] - preSum[mid + 1]) - - (preSum[mid] - preSum[i]) + (preSum[mid] - preSum[i]), ); } return res; diff --git a/minimum-amount-of-time-to-collect-garbage/index.ts b/minimum-amount-of-time-to-collect-garbage/index.ts index dd855ec3..5b7fbd06 100644 --- a/minimum-amount-of-time-to-collect-garbage/index.ts +++ b/minimum-amount-of-time-to-collect-garbage/index.ts @@ -2,7 +2,7 @@ import { groupBy } from "../deps.ts"; export default function garbageCollection( garbage: string[], - travel: number[] + travel: number[], ): number { const pre: number[] = Array(travel.length + 1).fill(0); let mc = 0; diff --git a/minimum-area-rectangle-ii/index.ts b/minimum-area-rectangle-ii/index.ts index 8ffeed02..d198532a 100644 --- a/minimum-area-rectangle-ii/index.ts +++ b/minimum-area-rectangle-ii/index.ts @@ -13,11 +13,10 @@ export default function minAreaFreeRect(points: number[][]): number { if ( 0 === - (p2[0] - p1[0]) * (p3[0] - p1[0]) + - (p2[1] - p1[1]) * (p3[1] - p1[1]) + (p2[0] - p1[0]) * (p3[0] - p1[0]) + + (p2[1] - p1[1]) * (p3[1] - p1[1]) ) { - const area = - Math.hypot(p2[1] - p1[1], p2[0] - p1[0]) * + const area = Math.hypot(p2[1] - p1[1], p2[0] - p1[0]) * Math.hypot(p3[1] - p1[1], p3[0] - p1[0]); if (area < ans && ps.has(JSON.stringify(p4))) { ans = area; diff --git a/minimum-area-rectangle/index.ts b/minimum-area-rectangle/index.ts index 6963ffb3..e00c5138 100644 --- a/minimum-area-rectangle/index.ts +++ b/minimum-area-rectangle/index.ts @@ -9,8 +9,7 @@ export default function minAreaRect(points: number[][]): number { points[i][0] !== points[j][0] && points[i][1] !== points[j][1] ) { - const area = - Math.abs(points[j][0] - points[i][0]) * + const area = Math.abs(points[j][0] - points[i][0]) * Math.abs(points[j][1] - points[i][1]); if (area > ans) continue; if ( diff --git a/minimum-changes-to-make-alternating-binary-string/index.ts b/minimum-changes-to-make-alternating-binary-string/index.ts index cd5b0c6f..d1b1120c 100644 --- a/minimum-changes-to-make-alternating-binary-string/index.ts +++ b/minimum-changes-to-make-alternating-binary-string/index.ts @@ -3,7 +3,7 @@ function minOperations(s: string): number { s, //@ts-ignore (p: number, c: string, i: number) => p + Number(i % 2 === Number(c)), - 0 + 0, ) as number; return Math.min(res, s.length - res); } diff --git a/minimum-cost-to-hire-k-workers/index.ts b/minimum-cost-to-hire-k-workers/index.ts index e4c51d64..40d9984f 100644 --- a/minimum-cost-to-hire-k-workers/index.ts +++ b/minimum-cost-to-hire-k-workers/index.ts @@ -2,7 +2,7 @@ export default mincostToHireWorkers; function mincostToHireWorkers( quality: number[], wage: number[], - k: number + k: number, ): number { const pairs = quality .map((q, i) => [q, wage[i]]) diff --git a/minimum-fuel-cost-to-report-to-the-capital/index.ts b/minimum-fuel-cost-to-report-to-the-capital/index.ts index e367469b..24642931 100644 --- a/minimum-fuel-cost-to-report-to-the-capital/index.ts +++ b/minimum-fuel-cost-to-report-to-the-capital/index.ts @@ -1,6 +1,6 @@ export default function minimumFuelCost( roads: number[][], - seats: number + seats: number, ): number { let ans = 0; const g = Array(roads.length + 1) diff --git a/minimum-index-sum-of-two-lists/index.ts b/minimum-index-sum-of-two-lists/index.ts index ba9e8075..7873a71d 100644 --- a/minimum-index-sum-of-two-lists/index.ts +++ b/minimum-index-sum-of-two-lists/index.ts @@ -1,18 +1,18 @@ export default function findRestaurant( list1: string[], - list2: string[] + list2: string[], ): string[] { const RestaurantToIndex1 = new Map( Array.from(list1.entries()).map(([index, restaurant]) => [ restaurant, index, - ]) + ]), ); const RestaurantToIndex2 = new Map( Array.from(list2.entries()).map(([index, restaurant]) => [ restaurant, index, - ]) + ]), ); const commonRestaurants = list1.filter((restaurant) => RestaurantToIndex2.has(restaurant) @@ -22,14 +22,14 @@ export default function findRestaurant( [ restaurant, (RestaurantToIndex1.get(restaurant) ?? 0) + - (RestaurantToIndex2.get(restaurant) ?? 0), - ] as const + (RestaurantToIndex2.get(restaurant) ?? 0), + ] as const, ); const minimumIndexSum = Math.min( - ...RestaurantsCommonToIndexSum.map((a) => a[1]) + ...RestaurantsCommonToIndexSum.map((a) => a[1]), ); return RestaurantsCommonToIndexSum.filter( - (a) => a[1] === minimumIndexSum + (a) => a[1] === minimumIndexSum, ).map((a) => a[0]); } diff --git a/minimum-moves-to-reach-target-with-rotations/index.ts b/minimum-moves-to-reach-target-with-rotations/index.ts index d8629c18..6ab6b1da 100644 --- a/minimum-moves-to-reach-target-with-rotations/index.ts +++ b/minimum-moves-to-reach-target-with-rotations/index.ts @@ -7,7 +7,7 @@ function bfs( grid: number[][], visited: Set, positions: [x: number, y: number, x: number, y: number][], - step: number + step: number, ): number { const n = grid.length; if (positions.length === 0) return -1; @@ -50,7 +50,7 @@ function hash(position: [x: number, y: number, x: number, y: number]): string { } function isEnd( position: [x: number, y: number, x: number, y: number], - n: number + n: number, ): boolean { return ( position[0] === n - 1 && diff --git a/minimum-number-of-moves-to-seat-everyone/index.ts b/minimum-number-of-moves-to-seat-everyone/index.ts index 7d3fe75d..242fc8e8 100644 --- a/minimum-number-of-moves-to-seat-everyone/index.ts +++ b/minimum-number-of-moves-to-seat-everyone/index.ts @@ -1,6 +1,6 @@ export default function minMovesToSeat( seats: number[], - students: number[] + students: number[], ): number { seats.sort((a, b) => a - b); students.sort((a, b) => a - b); diff --git a/minimum-number-of-refueling-stops/index.ts b/minimum-number-of-refueling-stops/index.ts index 8c2c64d7..d36805be 100644 --- a/minimum-number-of-refueling-stops/index.ts +++ b/minimum-number-of-refueling-stops/index.ts @@ -3,7 +3,7 @@ import { PriorityQueue } from "../kth-largest-element-in-a-stream/PriorityQueue. function minRefuelStops( target: number, startFuel: number, - stations: number[][] + stations: number[][], ): number { const pq = PriorityQueue((a, b) => b - a); diff --git a/minimum-path-sum/index.ts b/minimum-path-sum/index.ts index 4c7f0ed1..9111fb93 100644 --- a/minimum-path-sum/index.ts +++ b/minimum-path-sum/index.ts @@ -12,7 +12,7 @@ function minPathSum(grid: number[][]): number { return grid[i][j] + Math.min(dp(i - 1, j), dp(i, j - 1)); }, - (i, j) => i * n + j + (i, j) => i * n + j, ); return dp(m - 1, n - 1); } diff --git a/minimum-score-after-removals-on-a-tree/index.ts b/minimum-score-after-removals-on-a-tree/index.ts index 2309bb42..14ccb2c3 100644 --- a/minimum-score-after-removals-on-a-tree/index.ts +++ b/minimum-score-after-removals-on-a-tree/index.ts @@ -1,6 +1,6 @@ export default function minimumScore( nums: number[], - edges: number[][] + edges: number[][], ): number { const n = nums.length; if (nums.length === 0) return 0; @@ -56,7 +56,7 @@ function bfs( children: number[][], ancestorToGrandson: boolean[][], xor: number[], - nums: number[] + nums: number[], ) { if (nodes.length === 0) return; const temp: number[] = []; diff --git a/minimum-time-to-type-word-using-special-typewriter/index.ts b/minimum-time-to-type-word-using-special-typewriter/index.ts index 343ecd53..ec605534 100644 --- a/minimum-time-to-type-word-using-special-typewriter/index.ts +++ b/minimum-time-to-type-word-using-special-typewriter/index.ts @@ -2,11 +2,10 @@ function minTimeToType(word: string): number { let p = "a", ans = 0; for (const c of word) { - ans += - Math.min( - Math.abs(p.charCodeAt(0) - c.charCodeAt(0)), - 26 - Math.abs(c.charCodeAt(0) - p.charCodeAt(0)) - ) + 1; + ans += Math.min( + Math.abs(p.charCodeAt(0) - c.charCodeAt(0)), + 26 - Math.abs(c.charCodeAt(0) - p.charCodeAt(0)), + ) + 1; p = c; } return ans; diff --git a/minimum-total-distance-traveled/index.ts b/minimum-total-distance-traveled/index.ts index 18d7e39c..f5a57603 100644 --- a/minimum-total-distance-traveled/index.ts +++ b/minimum-total-distance-traveled/index.ts @@ -2,7 +2,7 @@ import memoize from "https://cdn.skypack.dev/lodash@4.17.21/memoize?dts"; export default function minimumTotalDistance( robot: number[], - factory: number[][] + factory: number[][], ): number { factory.sort((a, b) => a[0] - b[0]); robot.sort((a, b) => a - b); @@ -29,7 +29,7 @@ export default function minimumTotalDistance( return res; }, - (i: number, j: number) => JSON.stringify([i, j]) + (i: number, j: number) => JSON.stringify([i, j]), ); return dfs(0, 0); } diff --git a/missing-ranges/index.ts b/missing-ranges/index.ts index 474c9b5f..cda77aed 100644 --- a/missing-ranges/index.ts +++ b/missing-ranges/index.ts @@ -1,7 +1,7 @@ export default function findMissingRanges( nums: number[], lower: number, - upper: number + upper: number, ): string[] { const ans: string[] = []; nums.push(upper + 1); diff --git a/most-common-word/index.ts b/most-common-word/index.ts index 0251a93c..93833046 100644 --- a/most-common-word/index.ts +++ b/most-common-word/index.ts @@ -3,7 +3,7 @@ import { counter } from "../substring-with-concatenation-of-all-words/counter.ts function mostCommonWord(paragraph: string, banned: string[]): string { const ban = new Set(banned); const cnt = counter( - [...paragraph.matchAll(/\w+/g)].map((a) => a[0].toLowerCase()) + [...paragraph.matchAll(/\w+/g)].map((a) => a[0].toLowerCase()), ); return Array.from(cnt.entries()) .filter((k) => !ban.has(k[0])) diff --git a/most-frequent-even-element/index.ts b/most-frequent-even-element/index.ts index 93d16349..76cc161f 100644 --- a/most-frequent-even-element/index.ts +++ b/most-frequent-even-element/index.ts @@ -8,6 +8,6 @@ function mostFrequentEven(nums: number[]): number { const freq = Math.max(...cnt.values()); return Math.min( - ...[...cnt.entries()].filter(([_k, v]) => v === freq).map((a) => a[0]) + ...[...cnt.entries()].filter(([_k, v]) => v === freq).map((a) => a[0]), ); } diff --git a/most-profitable-path-in-a-tree/index.ts b/most-profitable-path-in-a-tree/index.ts index 8db5f17d..d65bcd64 100644 --- a/most-profitable-path-in-a-tree/index.ts +++ b/most-profitable-path-in-a-tree/index.ts @@ -1,7 +1,7 @@ export default function mostProfitablePath( edges: number[][], bob: number, - amount: number[] + amount: number[], ): number { const g: number[][] = amount.map(() => []); diff --git a/most-stones-removed-with-same-row-or-column/index.ts b/most-stones-removed-with-same-row-or-column/index.ts index fc34093e..89312109 100644 --- a/most-stones-removed-with-same-row-or-column/index.ts +++ b/most-stones-removed-with-same-row-or-column/index.ts @@ -4,7 +4,7 @@ export default function removeStones(stones: [number, number][]): number { function merge( ar: [row: number, col: number], - rp: Set<[row: number, col: number]> + rp: Set<[row: number, col: number]>, ) { parent_row.set(ar[0], rp); @@ -38,7 +38,7 @@ export default function removeStones(stones: [number, number][]): number { function combine( stone: [number, number], rp: Set<[row: number, col: number]> | undefined, - cp: Set<[row: number, col: number]> | undefined + cp: Set<[row: number, col: number]> | undefined, ) { const series: Set<[row: number, col: number]> = rp || cp || new Set(); diff --git a/multiply-strings/index.ts b/multiply-strings/index.ts index da16dde1..43089593 100644 --- a/multiply-strings/index.ts +++ b/multiply-strings/index.ts @@ -36,7 +36,7 @@ function multiply(x: string, y: string): string { const half = Math.floor(x.length / 2); return addStrings( multiply(y, x.slice(0, half)) + "0".repeat(x.length - half), - multiply(y, x.slice(half)) + multiply(y, x.slice(half)), ); } } else { @@ -44,7 +44,7 @@ function multiply(x: string, y: string): string { const half = Math.floor(y.length / 2); return addStrings( multiply(x, y.slice(0, half)) + "0".repeat(y.length - half), - multiply(x, y.slice(half)) + multiply(x, y.slice(half)), ); } } diff --git a/my-calendar-ii/index.ts b/my-calendar-ii/index.ts index 16e740eb..9269863c 100644 --- a/my-calendar-ii/index.ts +++ b/my-calendar-ii/index.ts @@ -4,7 +4,7 @@ import { searchSegmentLeaf } from "./searchSegmentLeaf.ts"; export default class MyCalendarTwo { #root: SegmentTree = SegmentTree( Number.MIN_SAFE_INTEGER, - Number.MAX_SAFE_INTEGER + Number.MAX_SAFE_INTEGER, ); // #result = 0; diff --git a/my-calendar-iii/index.ts b/my-calendar-iii/index.ts index e57d5bce..538a5fa0 100644 --- a/my-calendar-iii/index.ts +++ b/my-calendar-iii/index.ts @@ -4,7 +4,7 @@ import { SegmentTree } from "./SegmentTree.ts"; export default class MyCalendarThree { #root: SegmentTree = SegmentTree( Number.MIN_SAFE_INTEGER, - Number.MAX_SAFE_INTEGER + Number.MAX_SAFE_INTEGER, ); #result = 0; diff --git a/n-queens/index.ts b/n-queens/index.ts index dbf3612a..3f193131 100644 --- a/n-queens/index.ts +++ b/n-queens/index.ts @@ -17,7 +17,7 @@ export default function solveNQueens(n: number): string[][] { return line.join(""); }); solutions.push(s); - } + }, ); return solutions; } diff --git a/network-delay-time/index.ts b/network-delay-time/index.ts index 087bc9b0..4ffef13c 100644 --- a/network-delay-time/index.ts +++ b/network-delay-time/index.ts @@ -3,7 +3,7 @@ import { Heap } from "npm:@datastructures-js/heap@4.3.1"; export default function networkDelayTime( times: number[][], n: number, - k: number + k: number, ): number { const pq = new Heap<[number, number]>((a, b) => a[1] - b[1]); const edge = new Map(); diff --git a/next-greater-element-i/index.ts b/next-greater-element-i/index.ts index 10fe3bff..86a6d7ac 100644 --- a/next-greater-element-i/index.ts +++ b/next-greater-element-i/index.ts @@ -1,6 +1,6 @@ export default function nextGreaterElement( nums1: number[], - nums2: number[] + nums2: number[], ): number[] { const map: Map = new Map(); const stack = []; diff --git a/next-greater-node-in-linked-list/index.ts b/next-greater-node-in-linked-list/index.ts index 7a47fdf3..1866b10c 100644 --- a/next-greater-node-in-linked-list/index.ts +++ b/next-greater-node-in-linked-list/index.ts @@ -25,7 +25,7 @@ export default function nextLargerNodes(head: ListNode | null): number[] { res.push( monotoneStack.length > 0 ? monotoneStack[monotoneStack.length - 1] - : 0 + : 0, ); monotoneStack.push(node.val); } diff --git a/nge-tou-zi-de-dian-shu-lcof/index.ts b/nge-tou-zi-de-dian-shu-lcof/index.ts index e50e22e6..7e8b6637 100644 --- a/nge-tou-zi-de-dian-shu-lcof/index.ts +++ b/nge-tou-zi-de-dian-shu-lcof/index.ts @@ -12,14 +12,9 @@ function dfs(n: number, s: number): number { const cached = cache[n]?.[s]; if (typeof cached !== "undefined") return cached; - const res: number = - n === 0 - ? 1 - : s < n || s > 6 * n - ? 0 - : Array(6) - .fill(0) - .reduce((p, _, i) => p + dfs(n - 1, s - (i + 1)), 0); + const res: number = n === 0 ? 1 : s < n || s > 6 * n ? 0 : Array(6) + .fill(0) + .reduce((p, _, i) => p + dfs(n - 1, s - (i + 1)), 0); cache[n] ??= []; cache[n][s] = res; diff --git a/nth-magical-number/index.ts b/nth-magical-number/index.ts index 9177bf1d..b6c412a7 100644 --- a/nth-magical-number/index.ts +++ b/nth-magical-number/index.ts @@ -1,7 +1,7 @@ export default function nthMagicalNumber( n: number, a: number, - b: number + b: number, ): number { const MOD = 1000000007; diff --git a/number-of-arithmetic-triplets/index.ts b/number-of-arithmetic-triplets/index.ts index 74d4877e..f0525055 100644 --- a/number-of-arithmetic-triplets/index.ts +++ b/number-of-arithmetic-triplets/index.ts @@ -1,10 +1,10 @@ export default function arithmeticTriplets( nums: number[], - diff: number + diff: number, ): number { const set = new Set(nums); return nums.reduce( (a, v) => a + Number(set.has(v - diff) && set.has(v - 2 * diff)), - 0 + 0, ); } diff --git a/number-of-different-integers-in-a-string/index.ts b/number-of-different-integers-in-a-string/index.ts index 7b12e1cf..ba45eda8 100644 --- a/number-of-different-integers-in-a-string/index.ts +++ b/number-of-different-integers-in-a-string/index.ts @@ -3,6 +3,6 @@ export default function numDifferentIntegers(word: string): number { word .split(/[^\d]+/) .filter(Boolean) - .map(BigInt) + .map(BigInt), ).size; } diff --git a/number-of-good-pairs/index.ts b/number-of-good-pairs/index.ts index 86d426e6..46ac14b6 100644 --- a/number-of-good-pairs/index.ts +++ b/number-of-good-pairs/index.ts @@ -5,7 +5,7 @@ export default function numIdenticalPairs(nums: number[]): number { } const ans = Array.from(cnt.values()).reduce( (a, v) => a + Math.floor((v * (v - 1)) / 2), - 0 + 0, ); return ans; } diff --git a/number-of-good-paths/index.ts b/number-of-good-paths/index.ts index ed6537f2..7c99d108 100644 --- a/number-of-good-paths/index.ts +++ b/number-of-good-paths/index.ts @@ -11,7 +11,7 @@ function numberOfGoodPaths(vals: number[], edges: number[][]): number { } edges.sort( (a, b) => - Math.max(vals[a[0]], vals[a[1]]) - Math.max(vals[b[0]], vals[b[1]]) + Math.max(vals[a[0]], vals[a[1]]) - Math.max(vals[b[0]], vals[b[1]]), ); const uf = new UnionFind(); let ans = n; @@ -36,7 +36,7 @@ function numberOfGoodPaths(vals: number[], edges: number[][]): number { ans += [...count.values()].reduce( (p, c) => p + Math.floor((c * (c - 1)) / 2), - 0 + 0, ); } return ans; diff --git a/number-of-pairs-satisfying-inequality/index.ts b/number-of-pairs-satisfying-inequality/index.ts index 3ad81dd0..4a63c6d5 100644 --- a/number-of-pairs-satisfying-inequality/index.ts +++ b/number-of-pairs-satisfying-inequality/index.ts @@ -4,7 +4,7 @@ import { lowerBound } from "./lowerBound.ts"; export default function numberOfPairs( nums1: number[], nums2: number[], - diff: number + diff: number, ): number { for (const [i, x] of nums2.entries()) { nums1[i] -= x; diff --git a/number-of-provinces/index.ts b/number-of-provinces/index.ts index 29631ef5..07690ccb 100644 --- a/number-of-provinces/index.ts +++ b/number-of-provinces/index.ts @@ -18,9 +18,11 @@ export default function findCircleNum(isConnected: number[][]): number { } cache.add(i); - for (const [j] of [...isConnected[i].entries()].filter( - ([j, v]) => v === 1 && i !== j - )) { + for ( + const [j] of [...isConnected[i].entries()].filter( + ([j, v]) => v === 1 && i !== j, + ) + ) { dfs(j); } } diff --git a/number-of-students-doing-homework-at-a-given-time/index.ts b/number-of-students-doing-homework-at-a-given-time/index.ts index af2e2a77..7e3b08c6 100644 --- a/number-of-students-doing-homework-at-a-given-time/index.ts +++ b/number-of-students-doing-homework-at-a-given-time/index.ts @@ -1,7 +1,7 @@ export default function busyStudent( startTime: number[], endTime: number[], - queryTime: number + queryTime: number, ): number { return startTime .map((s, i) => Number(queryTime <= endTime[i] && queryTime >= s)) diff --git a/number-of-students-unable-to-eat-lunch/index.ts b/number-of-students-unable-to-eat-lunch/index.ts index 0c403b10..66a5a65e 100644 --- a/number-of-students-unable-to-eat-lunch/index.ts +++ b/number-of-students-unable-to-eat-lunch/index.ts @@ -1,6 +1,6 @@ export default function countStudents( students: number[], - sandwiches: number[] + sandwiches: number[], ): number { const cnt = Object.assign([0, 0], countBy(students)); diff --git a/number-of-subarrays-with-bounded-maximum/index.ts b/number-of-subarrays-with-bounded-maximum/index.ts index 272deb59..75e320fc 100644 --- a/number-of-subarrays-with-bounded-maximum/index.ts +++ b/number-of-subarrays-with-bounded-maximum/index.ts @@ -1,7 +1,7 @@ function numSubarrayBoundedMax( nums: number[], left: number, - right: number + right: number, ): number { return count(nums, right) - count(nums, left - 1); } diff --git a/number-of-ways-to-buy-pens-and-pencils/index.ts b/number-of-ways-to-buy-pens-and-pencils/index.ts index c44ff2d6..489ce268 100644 --- a/number-of-ways-to-buy-pens-and-pencils/index.ts +++ b/number-of-ways-to-buy-pens-and-pencils/index.ts @@ -1,14 +1,14 @@ export default function waysToBuyPensPencils( total: number, cost1: number, - cost2: number + cost2: number, ): number { if (cost1 < cost2) { [cost1, cost2] = [cost2, cost1]; } return iterate(Array(Math.floor(total / cost1 + 1)).keys()).reduce( (a, i) => a + Math.floor(1 + (total - cost1 * i) / cost2), - 0 + 0, ); } diff --git a/numbers-at-most-n-given-digit-set/index.ts b/numbers-at-most-n-given-digit-set/index.ts index ee1c5f1e..3fc6d763 100644 --- a/numbers-at-most-n-given-digit-set/index.ts +++ b/numbers-at-most-n-given-digit-set/index.ts @@ -1,18 +1,17 @@ export default function atMostNGivenDigitSet( digits: string[], - n: number + n: number, ): number { const s = String(n); const len = s.length; let ans = [...Array(len - 1).keys()].reduce( (a, i) => a + Math.pow(digits.length, i + 1), - 0 + 0, ); // console.log(ans) for (const [i, c] of s.split("").entries()) { - ans += - Math.pow(digits.length, len - i - 1) * + ans += Math.pow(digits.length, len - i - 1) * digits.filter((d) => d < c).length; if (!digits.includes(c)) return ans; diff --git a/numbers-with-repeated-digits/index.ts b/numbers-with-repeated-digits/index.ts index 96fde1e4..1992f718 100644 --- a/numbers-with-repeated-digits/index.ts +++ b/numbers-with-repeated-digits/index.ts @@ -1,7 +1,8 @@ export default function numDupDigitsAtMostN(n: number): number { const s = String(n), - dp: number[][] = Array.from({ length: s.length }, () => - Array(1 << 10).fill(-1) + dp: number[][] = Array.from( + { length: s.length }, + () => Array(1 << 10).fill(-1), ); /** @@ -15,7 +16,7 @@ export default function numDupDigitsAtMostN(n: number): number { i: number, mask: number, isLimit: boolean, - isNum: boolean + isNum: boolean, ): number { // 这次已经终点, 如果填过, 次数+1 if (i === s.length) return isNum ? 1 : 0; diff --git a/o8SXZn/index.ts b/o8SXZn/index.ts index 6eec6167..269a0934 100644 --- a/o8SXZn/index.ts +++ b/o8SXZn/index.ts @@ -6,7 +6,7 @@ function storeWater(bucket: number[], vat: number[]): number { ...Array(m - 1) .fill(0) .map((_, i) => i + 1) - .map((i) => count(bucket, vat, i)) + .map((i) => count(bucket, vat, i)), ); } function count(bucket: number[], vat: number[], i: number): number { diff --git a/pacific-atlantic-water-flow/index.ts b/pacific-atlantic-water-flow/index.ts index 9e906b0b..21d5a72b 100644 --- a/pacific-atlantic-water-flow/index.ts +++ b/pacific-atlantic-water-flow/index.ts @@ -29,7 +29,7 @@ export default function pacificAtlantic(heights: number[][]): number[][] { (pos) => { const [x, y] = pos.split(","); return [Number(x), Number(y)]; - } + }, ); return result; @@ -41,7 +41,7 @@ function dfs( m: number, n: number, pacific: Set<`${number},${number}`>, - heights: number[][] + heights: number[][], ) { const dirs = [ [-1, 0], diff --git a/parse-lisp-expression/index.ts b/parse-lisp-expression/index.ts index e9e36c3a..9afcc7bc 100644 --- a/parse-lisp-expression/index.ts +++ b/parse-lisp-expression/index.ts @@ -89,7 +89,7 @@ function parseList(expression: string): ListArray { .replaceAll("(", "[") .replaceAll(")", "]") .replaceAll(" ", ",") - .replaceAll(/[a-z]([a-z]|\d)*/g, (a) => '"' + a + '"') + .replaceAll(/[a-z]([a-z]|\d)*/g, (a) => '"' + a + '"'), ); } @@ -149,7 +149,7 @@ function calculate(expression: Expression, scope: ScopeList): number { expression.declarations.forEach((declaration) => { newScope.variables.set( declaration.id.name, - calculate(declaration.init, newScope) + calculate(declaration.init, newScope), ); }); return calculate(expression.return.argument, newScope); @@ -165,7 +165,7 @@ export type Expression = export class ScopeList { constructor( public readonly variables: Map = new Map(), - public parent: ScopeList | null | undefined = null + public parent: ScopeList | null | undefined = null, ) {} } export interface VariableDeclarator { diff --git a/parsing-a-boolean-expression/index.ts b/parsing-a-boolean-expression/index.ts index 5e0ca636..8be61346 100644 --- a/parsing-a-boolean-expression/index.ts +++ b/parsing-a-boolean-expression/index.ts @@ -9,7 +9,7 @@ export default function parseBoolExpr(expression: string): boolean { expression.replace(/(\!|\&|\|)/g, (a) => { const value = translator.get(a); return value ?? a; - }) + }), )(true, false, not, and, or); } const translator = new Map([ diff --git a/partition-list/index.ts b/partition-list/index.ts index aca60b98..46f34916 100644 --- a/partition-list/index.ts +++ b/partition-list/index.ts @@ -4,7 +4,7 @@ import { ListNodeToArray } from "../reverse-linked-list/ListNodeToArray.ts"; export default function partition( head: ListNode | null, - x: number + x: number, ): ListNode | null { if (!head) return head; if (!head.next) return head; diff --git a/partition-to-k-equal-sum-subsets/index.ts b/partition-to-k-equal-sum-subsets/index.ts index 361ccdde..1a890023 100644 --- a/partition-to-k-equal-sum-subsets/index.ts +++ b/partition-to-k-equal-sum-subsets/index.ts @@ -1,6 +1,6 @@ export default function canPartitionKSubsets( nums: number[], - k: number + k: number, ): boolean { const sum = nums.reduce((a, v) => a + v, 0); if (sum % k != 0) return false; diff --git a/partitioning-into-minimum-number-of-deci-binary-numbers/index.ts b/partitioning-into-minimum-number-of-deci-binary-numbers/index.ts index 69f20f9a..d5c02bc3 100644 --- a/partitioning-into-minimum-number-of-deci-binary-numbers/index.ts +++ b/partitioning-into-minimum-number-of-deci-binary-numbers/index.ts @@ -1,7 +1,9 @@ export default function minPartitions(n: string): number { - for (const i of Array(10) - .fill(0) - .map((_v, i) => 10 - i - 1)) { + for ( + const i of Array(10) + .fill(0) + .map((_v, i) => 10 - i - 1) + ) { if (n.includes(String(i))) { return i; } diff --git a/pascals-triangle-ii/index.ts b/pascals-triangle-ii/index.ts index 1f8b80f0..823b9396 100644 --- a/pascals-triangle-ii/index.ts +++ b/pascals-triangle-ii/index.ts @@ -18,100 +18,516 @@ const cache = [ [1, 13, 78, 286, 715, 1287, 1716, 1716, 1287, 715, 286, 78, 13, 1], [1, 14, 91, 364, 1001, 2002, 3003, 3432, 3003, 2002, 1001, 364, 91, 14, 1], [ - 1, 15, 105, 455, 1365, 3003, 5005, 6435, 6435, 5005, 3003, 1365, 455, - 105, 15, 1, + 1, + 15, + 105, + 455, + 1365, + 3003, + 5005, + 6435, + 6435, + 5005, + 3003, + 1365, + 455, + 105, + 15, + 1, ], [ - 1, 16, 120, 560, 1820, 4368, 8008, 11440, 12870, 11440, 8008, 4368, - 1820, 560, 120, 16, 1, + 1, + 16, + 120, + 560, + 1820, + 4368, + 8008, + 11440, + 12870, + 11440, + 8008, + 4368, + 1820, + 560, + 120, + 16, + 1, ], [ - 1, 17, 136, 680, 2380, 6188, 12376, 19448, 24310, 24310, 19448, 12376, - 6188, 2380, 680, 136, 17, 1, + 1, + 17, + 136, + 680, + 2380, + 6188, + 12376, + 19448, + 24310, + 24310, + 19448, + 12376, + 6188, + 2380, + 680, + 136, + 17, + 1, ], [ - 1, 18, 153, 816, 3060, 8568, 18564, 31824, 43758, 48620, 43758, 31824, - 18564, 8568, 3060, 816, 153, 18, 1, + 1, + 18, + 153, + 816, + 3060, + 8568, + 18564, + 31824, + 43758, + 48620, + 43758, + 31824, + 18564, + 8568, + 3060, + 816, + 153, + 18, + 1, ], [ - 1, 19, 171, 969, 3876, 11628, 27132, 50388, 75582, 92378, 92378, 75582, - 50388, 27132, 11628, 3876, 969, 171, 19, 1, + 1, + 19, + 171, + 969, + 3876, + 11628, + 27132, + 50388, + 75582, + 92378, + 92378, + 75582, + 50388, + 27132, + 11628, + 3876, + 969, + 171, + 19, + 1, ], [ - 1, 20, 190, 1140, 4845, 15504, 38760, 77520, 125970, 167960, 184756, - 167960, 125970, 77520, 38760, 15504, 4845, 1140, 190, 20, 1, + 1, + 20, + 190, + 1140, + 4845, + 15504, + 38760, + 77520, + 125970, + 167960, + 184756, + 167960, + 125970, + 77520, + 38760, + 15504, + 4845, + 1140, + 190, + 20, + 1, ], [ - 1, 21, 210, 1330, 5985, 20349, 54264, 116280, 203490, 293930, 352716, - 352716, 293930, 203490, 116280, 54264, 20349, 5985, 1330, 210, 21, 1, + 1, + 21, + 210, + 1330, + 5985, + 20349, + 54264, + 116280, + 203490, + 293930, + 352716, + 352716, + 293930, + 203490, + 116280, + 54264, + 20349, + 5985, + 1330, + 210, + 21, + 1, ], [ - 1, 22, 231, 1540, 7315, 26334, 74613, 170544, 319770, 497420, 646646, - 705432, 646646, 497420, 319770, 170544, 74613, 26334, 7315, 1540, 231, - 22, 1, + 1, + 22, + 231, + 1540, + 7315, + 26334, + 74613, + 170544, + 319770, + 497420, + 646646, + 705432, + 646646, + 497420, + 319770, + 170544, + 74613, + 26334, + 7315, + 1540, + 231, + 22, + 1, ], [ - 1, 23, 253, 1771, 8855, 33649, 100947, 245157, 490314, 817190, 1144066, - 1352078, 1352078, 1144066, 817190, 490314, 245157, 100947, 33649, 8855, - 1771, 253, 23, 1, + 1, + 23, + 253, + 1771, + 8855, + 33649, + 100947, + 245157, + 490314, + 817190, + 1144066, + 1352078, + 1352078, + 1144066, + 817190, + 490314, + 245157, + 100947, + 33649, + 8855, + 1771, + 253, + 23, + 1, ], [ - 1, 24, 276, 2024, 10626, 42504, 134596, 346104, 735471, 1307504, - 1961256, 2496144, 2704156, 2496144, 1961256, 1307504, 735471, 346104, - 134596, 42504, 10626, 2024, 276, 24, 1, + 1, + 24, + 276, + 2024, + 10626, + 42504, + 134596, + 346104, + 735471, + 1307504, + 1961256, + 2496144, + 2704156, + 2496144, + 1961256, + 1307504, + 735471, + 346104, + 134596, + 42504, + 10626, + 2024, + 276, + 24, + 1, ], [ - 1, 25, 300, 2300, 12650, 53130, 177100, 480700, 1081575, 2042975, - 3268760, 4457400, 5200300, 5200300, 4457400, 3268760, 2042975, 1081575, - 480700, 177100, 53130, 12650, 2300, 300, 25, 1, + 1, + 25, + 300, + 2300, + 12650, + 53130, + 177100, + 480700, + 1081575, + 2042975, + 3268760, + 4457400, + 5200300, + 5200300, + 4457400, + 3268760, + 2042975, + 1081575, + 480700, + 177100, + 53130, + 12650, + 2300, + 300, + 25, + 1, ], [ - 1, 26, 325, 2600, 14950, 65780, 230230, 657800, 1562275, 3124550, - 5311735, 7726160, 9657700, 10400600, 9657700, 7726160, 5311735, 3124550, - 1562275, 657800, 230230, 65780, 14950, 2600, 325, 26, 1, + 1, + 26, + 325, + 2600, + 14950, + 65780, + 230230, + 657800, + 1562275, + 3124550, + 5311735, + 7726160, + 9657700, + 10400600, + 9657700, + 7726160, + 5311735, + 3124550, + 1562275, + 657800, + 230230, + 65780, + 14950, + 2600, + 325, + 26, + 1, ], [ - 1, 27, 351, 2925, 17550, 80730, 296010, 888030, 2220075, 4686825, - 8436285, 13037895, 17383860, 20058300, 20058300, 17383860, 13037895, - 8436285, 4686825, 2220075, 888030, 296010, 80730, 17550, 2925, 351, 27, + 1, + 27, + 351, + 2925, + 17550, + 80730, + 296010, + 888030, + 2220075, + 4686825, + 8436285, + 13037895, + 17383860, + 20058300, + 20058300, + 17383860, + 13037895, + 8436285, + 4686825, + 2220075, + 888030, + 296010, + 80730, + 17550, + 2925, + 351, + 27, 1, ], [ - 1, 28, 378, 3276, 20475, 98280, 376740, 1184040, 3108105, 6906900, - 13123110, 21474180, 30421755, 37442160, 40116600, 37442160, 30421755, - 21474180, 13123110, 6906900, 3108105, 1184040, 376740, 98280, 20475, - 3276, 378, 28, 1, + 1, + 28, + 378, + 3276, + 20475, + 98280, + 376740, + 1184040, + 3108105, + 6906900, + 13123110, + 21474180, + 30421755, + 37442160, + 40116600, + 37442160, + 30421755, + 21474180, + 13123110, + 6906900, + 3108105, + 1184040, + 376740, + 98280, + 20475, + 3276, + 378, + 28, + 1, ], [ - 1, 29, 406, 3654, 23751, 118755, 475020, 1560780, 4292145, 10015005, - 20030010, 34597290, 51895935, 67863915, 77558760, 77558760, 67863915, - 51895935, 34597290, 20030010, 10015005, 4292145, 1560780, 475020, - 118755, 23751, 3654, 406, 29, 1, + 1, + 29, + 406, + 3654, + 23751, + 118755, + 475020, + 1560780, + 4292145, + 10015005, + 20030010, + 34597290, + 51895935, + 67863915, + 77558760, + 77558760, + 67863915, + 51895935, + 34597290, + 20030010, + 10015005, + 4292145, + 1560780, + 475020, + 118755, + 23751, + 3654, + 406, + 29, + 1, ], [ - 1, 30, 435, 4060, 27405, 142506, 593775, 2035800, 5852925, 14307150, - 30045015, 54627300, 86493225, 119759850, 145422675, 155117520, - 145422675, 119759850, 86493225, 54627300, 30045015, 14307150, 5852925, - 2035800, 593775, 142506, 27405, 4060, 435, 30, 1, + 1, + 30, + 435, + 4060, + 27405, + 142506, + 593775, + 2035800, + 5852925, + 14307150, + 30045015, + 54627300, + 86493225, + 119759850, + 145422675, + 155117520, + 145422675, + 119759850, + 86493225, + 54627300, + 30045015, + 14307150, + 5852925, + 2035800, + 593775, + 142506, + 27405, + 4060, + 435, + 30, + 1, ], [ - 1, 31, 465, 4495, 31465, 169911, 736281, 2629575, 7888725, 20160075, - 44352165, 84672315, 141120525, 206253075, 265182525, 300540195, - 300540195, 265182525, 206253075, 141120525, 84672315, 44352165, - 20160075, 7888725, 2629575, 736281, 169911, 31465, 4495, 465, 31, 1, + 1, + 31, + 465, + 4495, + 31465, + 169911, + 736281, + 2629575, + 7888725, + 20160075, + 44352165, + 84672315, + 141120525, + 206253075, + 265182525, + 300540195, + 300540195, + 265182525, + 206253075, + 141120525, + 84672315, + 44352165, + 20160075, + 7888725, + 2629575, + 736281, + 169911, + 31465, + 4495, + 465, + 31, + 1, ], [ - 1, 32, 496, 4960, 35960, 201376, 906192, 3365856, 10518300, 28048800, - 64512240, 129024480, 225792840, 347373600, 471435600, 565722720, - 601080390, 565722720, 471435600, 347373600, 225792840, 129024480, - 64512240, 28048800, 10518300, 3365856, 906192, 201376, 35960, 4960, 496, - 32, 1, + 1, + 32, + 496, + 4960, + 35960, + 201376, + 906192, + 3365856, + 10518300, + 28048800, + 64512240, + 129024480, + 225792840, + 347373600, + 471435600, + 565722720, + 601080390, + 565722720, + 471435600, + 347373600, + 225792840, + 129024480, + 64512240, + 28048800, + 10518300, + 3365856, + 906192, + 201376, + 35960, + 4960, + 496, + 32, + 1, ], [ - 1, 33, 528, 5456, 40920, 237336, 1107568, 4272048, 13884156, 38567100, - 92561040, 193536720, 354817320, 573166440, 818809200, 1037158320, - 1166803110, 1166803110, 1037158320, 818809200, 573166440, 354817320, - 193536720, 92561040, 38567100, 13884156, 4272048, 1107568, 237336, - 40920, 5456, 528, 33, 1, + 1, + 33, + 528, + 5456, + 40920, + 237336, + 1107568, + 4272048, + 13884156, + 38567100, + 92561040, + 193536720, + 354817320, + 573166440, + 818809200, + 1037158320, + 1166803110, + 1166803110, + 1037158320, + 818809200, + 573166440, + 354817320, + 193536720, + 92561040, + 38567100, + 13884156, + 4272048, + 1107568, + 237336, + 40920, + 5456, + 528, + 33, + 1, ], ]; diff --git a/path-sum-ii/index.ts b/path-sum-ii/index.ts index d0e96f38..ef00a1e9 100644 --- a/path-sum-ii/index.ts +++ b/path-sum-ii/index.ts @@ -11,7 +11,7 @@ function dfs( root: TreeNode, target: number, route: number[], - output: (route: number[]) => void + output: (route: number[]) => void, ) { if (!root.left && !root.right && target === root.val) { output([...route, root.val]); diff --git a/path-sum/index.ts b/path-sum/index.ts index c91da828..86c3e2e9 100644 --- a/path-sum/index.ts +++ b/path-sum/index.ts @@ -2,7 +2,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function hasPathSum( root: TreeNode | null, - targetSum: number + targetSum: number, ): boolean { if (!root) { return false; diff --git a/paths-with-sum-lcci/index.ts b/paths-with-sum-lcci/index.ts index acc1e8ea..eff1bc60 100644 --- a/paths-with-sum-lcci/index.ts +++ b/paths-with-sum-lcci/index.ts @@ -5,7 +5,7 @@ export default function pathSum(root: TreeNode | null, sum: number): number { root: TreeNode | null, prefix: Map, curr: number, - sum: number + sum: number, ) { if (root == null) { return 0; diff --git a/percentage-of-letter-in-string/index.ts b/percentage-of-letter-in-string/index.ts index 0d8de011..5880d5da 100644 --- a/percentage-of-letter-in-string/index.ts +++ b/percentage-of-letter-in-string/index.ts @@ -4,6 +4,6 @@ export default function percentageLetter(s: string, letter: string): number { //@ts-ignore (Array.prototype.reduce.call(s, (a, v) => a + Number(v === letter), 0) / s.length) * - 100 + 100, ); } diff --git a/permutations-ii/index.ts b/permutations-ii/index.ts index 27b1c64a..9c8f6a19 100644 --- a/permutations-ii/index.ts +++ b/permutations-ii/index.ts @@ -34,9 +34,12 @@ function permute_index(nums: number[], output: (indexs: number[]) => void) { arrays.push(b); } - for (const res of uniqBy(arrays, (a: number[]) => - Array.prototype.join.call(a, ",") - )) { + for ( + const res of uniqBy( + arrays, + (a: number[]) => Array.prototype.join.call(a, ","), + ) + ) { output(res); } }); diff --git a/possible-bipartition/index.ts b/possible-bipartition/index.ts index 93c4292c..87f68608 100644 --- a/possible-bipartition/index.ts +++ b/possible-bipartition/index.ts @@ -2,7 +2,7 @@ import { UnionFind } from "../largest-component-size-by-common-factor/UnionFind. export default function possibleBipartition( n: number, - dislikes: number[][] + dislikes: number[][], ): boolean { const uf = new UnionFind(); diff --git a/powx-n/index.ts b/powx-n/index.ts index 47738807..79ed1077 100644 --- a/powx-n/index.ts +++ b/powx-n/index.ts @@ -17,21 +17,20 @@ export default function myPow(x: number, n: number): number { if (n === -Infinity) { return x === 0 ? Infinity : 0; } - const result = - n === 1 - ? x - : x < 0 - ? (n % 2 === 0 ? 1 : -1) * myPow(-x, n) - : x === 1 - ? 1 - : x === 0 - ? 0 - : n === 0 - ? 1 - : n < 0 - ? myPow(1 / x, -n) - : n % 2 - ? x * myPow(x, n - 1) - : myPow(x * x, Math.floor(n / 2)); + const result = n === 1 + ? x + : x < 0 + ? (n % 2 === 0 ? 1 : -1) * myPow(-x, n) + : x === 1 + ? 1 + : x === 0 + ? 0 + : n === 0 + ? 1 + : n < 0 + ? myPow(1 / x, -n) + : n % 2 + ? x * myPow(x, n - 1) + : myPow(x * x, Math.floor(n / 2)); return result; } diff --git a/prime-arrangements/index.ts b/prime-arrangements/index.ts index 6ad6edcb..9a018597 100644 --- a/prime-arrangements/index.ts +++ b/prime-arrangements/index.ts @@ -3,18 +3,105 @@ export default function numPrimeArrangements(n: number): number { } const ans = [ - 1, 1, 1, 2, 4, 12, 36, 144, 576, 2880, 17280, 86400, 604800, 3628800, - 29030400, 261273600, 612735986, 289151874, 180670593, 445364737, 344376809, - 476898489, 676578804, 89209194, 338137903, 410206413, 973508979, 523161503, - 940068494, 400684877, 13697484, 150672324, 164118783, 610613205, 44103617, - 58486801, 462170018, 546040181, 197044608, 320204381, 965722612, 554393872, - 77422176, 83910457, 517313696, 36724464, 175182841, 627742601, 715505693, - 327193394, 451768713, 263673556, 755921509, 94744060, 600274259, 410695940, - 427837488, 541336889, 736149184, 514536044, 125049738, 250895270, 39391803, - 772631128, 541031643, 428487046, 567378068, 780183222, 228977612, 448880523, - 892906519, 858130261, 622773264, 78238453, 146637981, 918450925, 514800525, - 828829204, 243264299, 351814543, 405243354, 909357725, 561463122, 913651722, - 732754657, 430788419, 139670208, 938893256, 28061213, 673469112, 448961084, - 80392418, 466684389, 201222617, 85583092, 76399490, 500763245, 519081041, - 892915734, 75763854, 682289015, + 1, + 1, + 1, + 2, + 4, + 12, + 36, + 144, + 576, + 2880, + 17280, + 86400, + 604800, + 3628800, + 29030400, + 261273600, + 612735986, + 289151874, + 180670593, + 445364737, + 344376809, + 476898489, + 676578804, + 89209194, + 338137903, + 410206413, + 973508979, + 523161503, + 940068494, + 400684877, + 13697484, + 150672324, + 164118783, + 610613205, + 44103617, + 58486801, + 462170018, + 546040181, + 197044608, + 320204381, + 965722612, + 554393872, + 77422176, + 83910457, + 517313696, + 36724464, + 175182841, + 627742601, + 715505693, + 327193394, + 451768713, + 263673556, + 755921509, + 94744060, + 600274259, + 410695940, + 427837488, + 541336889, + 736149184, + 514536044, + 125049738, + 250895270, + 39391803, + 772631128, + 541031643, + 428487046, + 567378068, + 780183222, + 228977612, + 448880523, + 892906519, + 858130261, + 622773264, + 78238453, + 146637981, + 918450925, + 514800525, + 828829204, + 243264299, + 351814543, + 405243354, + 909357725, + 561463122, + 913651722, + 732754657, + 430788419, + 139670208, + 938893256, + 28061213, + 673469112, + 448961084, + 80392418, + 466684389, + 201222617, + 85583092, + 76399490, + 500763245, + 519081041, + 892915734, + 75763854, + 682289015, ]; diff --git a/print-immutable-linked-list-in-reverse/index.ts b/print-immutable-linked-list-in-reverse/index.ts index a8ed96fa..74879d37 100644 --- a/print-immutable-linked-list-in-reverse/index.ts +++ b/print-immutable-linked-list-in-reverse/index.ts @@ -1,7 +1,7 @@ import { ImmutableListNode } from "./ImmutableListNode.ts"; export default function printLinkedListInReverse( - head: ImmutableListNode | null + head: ImmutableListNode | null, ) { if (head !== null) { printLinkedListInReverse(head.getNext()); diff --git a/queries-on-number-of-points-inside-a-circle/index.ts b/queries-on-number-of-points-inside-a-circle/index.ts index e1d2f04a..00795196 100644 --- a/queries-on-number-of-points-inside-a-circle/index.ts +++ b/queries-on-number-of-points-inside-a-circle/index.ts @@ -1,6 +1,6 @@ export default function countPoints( points: number[][], - queries: number[][] + queries: number[][], ): number[] { return queries.map(([x, y, r]) => { return points.reduce((a, [n, m]) => { @@ -13,7 +13,7 @@ function point_in_circle( m: number, x: number, y: number, - r: number + r: number, ): boolean { return r ** 2 - (n - x) ** 2 - (y - m) ** 2 >= 0; // return n <= x + r && m <= y + r && n >= x - r && m >= y - r diff --git a/random-pick-index/index.ts b/random-pick-index/index.ts index 67635f1e..a76b5ec2 100644 --- a/random-pick-index/index.ts +++ b/random-pick-index/index.ts @@ -4,8 +4,7 @@ interface Solution { function Solution(nums: number[]): Solution { const pos: Map = new Map(); for (const [i, num] of nums.entries()) { - const indices: number[] = - pos.get(num) ?? + const indices: number[] = pos.get(num) ?? (() => { const d: number[] = []; pos.set(num, d); diff --git a/random-pick-with-weight/index.ts b/random-pick-with-weight/index.ts index df69289a..2d82a35d 100644 --- a/random-pick-with-weight/index.ts +++ b/random-pick-with-weight/index.ts @@ -2,7 +2,7 @@ export default class Solution { #select: () => number; constructor(w: number[]) { this.#select = Selector( - w.map((v, i) => ({ result: i, chance: v })) + w.map((v, i) => ({ result: i, chance: v })), ).select; } diff --git a/random-point-in-non-overlapping-rectangles/index.ts b/random-point-in-non-overlapping-rectangles/index.ts index 28964625..1c39799b 100644 --- a/random-point-in-non-overlapping-rectangles/index.ts +++ b/random-point-in-non-overlapping-rectangles/index.ts @@ -8,7 +8,7 @@ export default class Solution { for (const rect of rects) { const [a, b, x, y] = rect; this.#arr.push( - this.#arr[this.#arr.length - 1] + (x - a + 1) * (y - b + 1) + this.#arr[this.#arr.length - 1] + (x - a + 1) * (y - b + 1), ); } } diff --git a/range-addition-ii/index.ts b/range-addition-ii/index.ts index 6103c499..07a35d5a 100644 --- a/range-addition-ii/index.ts +++ b/range-addition-ii/index.ts @@ -1,7 +1,7 @@ export default function maxCount( m: number, n: number, - ops: number[][] + ops: number[][], ): number { return ops .reduce(([a, b], [v, d]) => [Math.min(a, v), Math.min(b, d)], [m, n]) diff --git a/range-module/index.ts b/range-module/index.ts index 2841eb06..2909a20e 100644 --- a/range-module/index.ts +++ b/range-module/index.ts @@ -30,7 +30,7 @@ export default class RangeModule { #root: SegmentTree = SegmentTree( Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER, - 0 + 0, ); addRange(left: number, right: number): void { @@ -73,7 +73,7 @@ export default class RangeModule { } if ( node.children.every( - (child) => child.children.length === 0 && child.value === 0 + (child) => child.children.length === 0 && child.value === 0, ) ) { node.children.length = 0; diff --git a/range-product-queries-of-powers/index.ts b/range-product-queries-of-powers/index.ts index 557ce95c..916f3068 100644 --- a/range-product-queries-of-powers/index.ts +++ b/range-product-queries-of-powers/index.ts @@ -2,7 +2,7 @@ import { multiplicativeInverse } from "./multiplicativeInverse.ts"; export default function productQueries( n: number, - queries: number[][] + queries: number[][], ): number[] { const powers = [1n]; const mod = BigInt(1e9 + 7); @@ -14,7 +14,8 @@ export default function productQueries( return queries.map(([left, right]) => { return Number( - (powers[right + 1] * multiplicativeInverse(powers[left], mod)) % mod + (powers[right + 1] * multiplicativeInverse(powers[left], mod)) % + mod, ); }); } diff --git a/range-sum-of-bst/index.ts b/range-sum-of-bst/index.ts index 471c9c79..1a949017 100644 --- a/range-sum-of-bst/index.ts +++ b/range-sum-of-bst/index.ts @@ -3,7 +3,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function rangeSumBST( root: TreeNode | null, low: number, - high: number + high: number, ): number { if (!root) { return 0; @@ -24,7 +24,7 @@ function level( nodes: TreeNode[], low: number, high: number, - output: (r: number[]) => void + output: (r: number[]) => void, ) { if (nodes.length === 0) { return; @@ -47,6 +47,6 @@ function level( .filter(Boolean) as TreeNode[], low, high, - output + output, ); } diff --git a/range-sum-query-2d-immutable/index.ts b/range-sum-query-2d-immutable/index.ts index 37a3b135..1c532303 100644 --- a/range-sum-query-2d-immutable/index.ts +++ b/range-sum-query-2d-immutable/index.ts @@ -10,8 +10,8 @@ export default function NumMatrix(matrix: number[][]): NumMatrix { ); matrix.forEach((a, i) => a.forEach((v, j) => { - sums[i + 1][j + 1] = - sums[i][j + 1] + sums[i + 1][j] - sums[i][j] + v; + sums[i + 1][j + 1] = sums[i][j + 1] + sums[i + 1][j] - sums[i][j] + + v; }) ); return { @@ -19,7 +19,7 @@ export default function NumMatrix(matrix: number[][]): NumMatrix { row1: number, col1: number, row2: number, - col2: number + col2: number, ): number { return ( sums[row2 + 1][col2 + 1] - diff --git a/range-sum-query-mutable/index.ts b/range-sum-query-mutable/index.ts index b406880e..b6844465 100644 --- a/range-sum-query-mutable/index.ts +++ b/range-sum-query-mutable/index.ts @@ -20,7 +20,7 @@ export function build( node: TreeNode, start: number, end: number, - nums: number[] + nums: number[], ) { if (start === end) { node.val = nums[start]; @@ -38,7 +38,7 @@ export function change( val: number, node: TreeNode, start: number, - end: number + end: number, ): void { if (start === end) { node.val = val; @@ -60,7 +60,7 @@ export function query( right: number, node: TreeNode, start: number, - end: number + end: number, ): number { if (start === left && right === end) { return node.val; diff --git a/reachable-nodes-in-subdivided-graph/index.ts b/reachable-nodes-in-subdivided-graph/index.ts index 001f9c68..c642e68b 100644 --- a/reachable-nodes-in-subdivided-graph/index.ts +++ b/reachable-nodes-in-subdivided-graph/index.ts @@ -1,7 +1,7 @@ export default function reachableNodes( edges: number[][], maxMoves: number, - n: number + n: number, ): number { const adList: [number, number][][] = Array(n) .fill(0) @@ -39,7 +39,7 @@ export default function reachableNodes( reachableNodes += Math.min( c, (used.get(JSON.stringify([u, v])) ?? 0) + - (used.get(JSON.stringify([v, u])) ?? 0) + (used.get(JSON.stringify([v, u])) ?? 0), ); } return reachableNodes; diff --git a/read-n-characters-given-read4/index.ts b/read-n-characters-given-read4/index.ts index 4150b1ee..8f0a15a2 100644 --- a/read-n-characters-given-read4/index.ts +++ b/read-n-characters-given-read4/index.ts @@ -1,20 +1,20 @@ export default (read4: (buf: string[]) => number) => - (buf: string[], n: number): number => { - const tmp: string[] = Array(4).fill(""); +(buf: string[], n: number): number => { + const tmp: string[] = Array(4).fill(""); - let total = 0; + let total = 0; - let eof = false; + let eof = false; - while (!eof && total < n) { - let count = read4(tmp); + while (!eof && total < n) { + let count = read4(tmp); - eof = count < 4; - count = Math.min(count, n - total); + eof = count < 4; + count = Math.min(count, n - total); - for (let i = 0; i < count; i++) { - buf[total++] = tmp[i]; - } + for (let i = 0; i < count; i++) { + buf[total++] = tmp[i]; } - return total; - }; + } + return total; +}; diff --git a/rearrange-characters-to-make-target-string/index.ts b/rearrange-characters-to-make-target-string/index.ts index caf2c02a..b9d8495d 100644 --- a/rearrange-characters-to-make-target-string/index.ts +++ b/rearrange-characters-to-make-target-string/index.ts @@ -1,7 +1,6 @@ function rearrangeCharacters(s: string, target: string): number { - - const sCounts = new Map(); - const targetCounts = new Map(); + const sCounts = new Map(); + const targetCounts = new Map(); const n = s.length, m = target.length; for (let i = 0; i < m; i++) { const c = target[i]; @@ -15,7 +14,7 @@ function rearrangeCharacters(s: string, target: string): number { } let ans = Number.MAX_VALUE; for (const [c, count] of targetCounts) { - const totalCount =( sCounts.has(c) ? sCounts.get(c) : 0)??0; + const totalCount = (sCounts.has(c) ? sCounts.get(c) : 0) ?? 0; ans = Math.min(ans, Math.floor(totalCount / count)); if (ans === 0) { return 0; @@ -23,4 +22,4 @@ function rearrangeCharacters(s: string, target: string): number { } return ans; } -export default rearrangeCharacters +export default rearrangeCharacters; diff --git a/rearrange-spaces-between-words/index.ts b/rearrange-spaces-between-words/index.ts index c9a1a780..6368150c 100644 --- a/rearrange-spaces-between-words/index.ts +++ b/rearrange-spaces-between-words/index.ts @@ -7,7 +7,7 @@ export default function reorderSpaces(text: string): string { text, //@ts-ignore (a, v) => a + Number(v === " "), - 0 + 0, ) as number; if (words.length <= 1) return words.join("") + " ".repeat(spaces); diff --git a/reconstruct-original-digits-from-english/index.ts b/reconstruct-original-digits-from-english/index.ts index 3dce3740..aa61f0e7 100644 --- a/reconstruct-original-digits-from-english/index.ts +++ b/reconstruct-original-digits-from-english/index.ts @@ -4,7 +4,7 @@ export default function originalDigits(str: string): string { const cnt = counter(str); const [z, o, w, u, r, x, s, v, t, n] = Array.prototype.map.call( "zowurxsvtn", - (v) => cnt.get(v) ?? 0 + (v) => cnt.get(v) ?? 0, ) as number[]; return [ z, diff --git a/recover-a-tree-from-preorder-traversal/index.ts b/recover-a-tree-from-preorder-traversal/index.ts index 4164d1c8..753e80e3 100644 --- a/recover-a-tree-from-preorder-traversal/index.ts +++ b/recover-a-tree-from-preorder-traversal/index.ts @@ -1,7 +1,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function recoverFromPreorder( - traversal: string + traversal: string, ): TreeNode | null { const depth_to_tree = new Map(); for (const [depth, value] of parse(traversal)) { diff --git a/rectangle-area-ii/index.ts b/rectangle-area-ii/index.ts index 2281d1ff..cfe541f8 100644 --- a/rectangle-area-ii/index.ts +++ b/rectangle-area-ii/index.ts @@ -37,19 +37,17 @@ function change(node: SegmentNode, target: Interval, value: bigint) { } } else { if (node.children.length === 0) { - const midx = - [target.left, target.right].filter( - (a) => current.left < a && current.right > a - )[0] ?? current.right; - const midy = - [target.down, target.up].filter( - (a) => current.down < a && current.up > a - )[0] ?? current.up; + const midx = [target.left, target.right].filter( + (a) => current.left < a && current.right > a, + )[0] ?? current.right; + const midy = [target.down, target.up].filter( + (a) => current.down < a && current.up > a, + )[0] ?? current.up; const subinterval = TwoDSplit(current, midx, midy); if (subinterval.length) { node.children = subinterval.map( - (c) => new SegmentNode(c, area(c) * BigInt(node.value > 0)) + (c) => new SegmentNode(c, area(c) * BigInt(node.value > 0)), ); } } @@ -80,7 +78,7 @@ export function contains(target: Interval, current: Interval): boolean { export function TwoDSplit( current: Interval, midx: number, - midy: number + midy: number, ): Interval[] { const { left, right, up, down } = current; @@ -114,14 +112,14 @@ export function TwoDSplit( down === current.down && up === current.up && right === current.right - ) + ), ); } export class SegmentNode { constructor( public interval: Interval = new Interval(), public value: bigint = 0n, - public children: SegmentNode[] = [] + public children: SegmentNode[] = [], ) {} } export class Interval { @@ -129,7 +127,7 @@ export class Interval { public left = 0, public right = 0, public down = 0, - public up = 0 + public up = 0, ) {} } diff --git a/rectangle-area/index.ts b/rectangle-area/index.ts index 334572bc..1d70bcf8 100644 --- a/rectangle-area/index.ts +++ b/rectangle-area/index.ts @@ -6,14 +6,13 @@ export default function computeArea( bx1: number, by1: number, bx2: number, - by2: number + by2: number, ): number { const x1 = Math.max(ax1, bx1); const x2 = Math.min(ax2, bx2); const y1 = Math.max(ay1, by1); const y2 = Math.min(ay2, by2); - const allSquare = - Math.abs((ax2 - ax1) * (ay2 - ay1)) + + const allSquare = Math.abs((ax2 - ax1) * (ay2 - ay1)) + Math.abs((bx2 - bx1) * (by2 - by1)); if (x1 >= x2 || y1 >= y2) { return allSquare; diff --git a/rectangle-overlap/index.ts b/rectangle-overlap/index.ts index 17fa8547..8cc59830 100644 --- a/rectangle-overlap/index.ts +++ b/rectangle-overlap/index.ts @@ -1,6 +1,6 @@ export default function isRectangleOverlap( rec1: number[], - rec2: number[] + rec2: number[], ): boolean { return ( Math.min(rec1[2], rec2[2]) > Math.max(rec1[0], rec2[0]) && diff --git a/redundant-connection-ii/index.ts b/redundant-connection-ii/index.ts index 00055ac2..4829cf4f 100644 --- a/redundant-connection-ii/index.ts +++ b/redundant-connection-ii/index.ts @@ -18,9 +18,7 @@ function findRedundantDirectedConnection(edges: number[][]): number[] { } return confictEdge - ? circleEdge - ? [parent[confictEdge[1]], confictEdge[1]] - : confictEdge + ? circleEdge ? [parent[confictEdge[1]], confictEdge[1]] : confictEdge : circleEdge ?? []; } diff --git a/reformat-phone-number/index.ts b/reformat-phone-number/index.ts index d3714835..ee8ec523 100644 --- a/reformat-phone-number/index.ts +++ b/reformat-phone-number/index.ts @@ -6,8 +6,8 @@ export default function reformatNumber(number: string): string { .map((_, i) => str.slice(i * 3, i * 3 + 3)); if (arr[arr.length - 1].length === 1) { - arr[arr.length - 1] = - arr[arr.length - 2].slice(-1) + arr[arr.length - 1]; + arr[arr.length - 1] = arr[arr.length - 2].slice(-1) + + arr[arr.length - 1]; arr[arr.length - 2] = arr[arr.length - 2].slice(0, 2); } // console.log(arr) diff --git a/regions-cut-by-slashes/index.ts b/regions-cut-by-slashes/index.ts index 2fac3190..b7324d69 100644 --- a/regions-cut-by-slashes/index.ts +++ b/regions-cut-by-slashes/index.ts @@ -28,6 +28,6 @@ export default function regionsBySlashes(grid: string[]): number { } return [...new Array(n * n * 4).keys()].reduce( (p, c) => p + Number(uf.find(c) === c), - 0 + 0, ); } diff --git a/remove-duplicates-from-sorted-list-ii/index.ts b/remove-duplicates-from-sorted-list-ii/index.ts index 82fdbcf0..4af2d25c 100644 --- a/remove-duplicates-from-sorted-list-ii/index.ts +++ b/remove-duplicates-from-sorted-list-ii/index.ts @@ -1,5 +1,5 @@ export default function deleteDuplicates( - head: ListNode | null + head: ListNode | null, ): ListNode | null { if (!head) return head; diff --git a/remove-duplicates-from-sorted-list/index.ts b/remove-duplicates-from-sorted-list/index.ts index 62459a1b..f50321b8 100644 --- a/remove-duplicates-from-sorted-list/index.ts +++ b/remove-duplicates-from-sorted-list/index.ts @@ -1,7 +1,7 @@ import { ListNode } from "../reverse-linked-list/ListNode.ts"; export default function deleteDuplicates( - head: ListNode | null + head: ListNode | null, ): ListNode | null { if (!head) return head; diff --git a/remove-linked-list-elements/index.ts b/remove-linked-list-elements/index.ts index ed909fd3..7338b3ef 100644 --- a/remove-linked-list-elements/index.ts +++ b/remove-linked-list-elements/index.ts @@ -2,7 +2,7 @@ import { ListNode } from "../reverse-linked-list/ListNode.ts"; export default function removeElements( head: ListNode | null, - val: number + val: number, ): ListNode | null { if (!head) { return head; diff --git a/remove-nth-node-from-end-of-list/index.ts b/remove-nth-node-from-end-of-list/index.ts index 764b7ff7..1a927013 100644 --- a/remove-nth-node-from-end-of-list/index.ts +++ b/remove-nth-node-from-end-of-list/index.ts @@ -2,7 +2,7 @@ import { ListNode } from "../reverse-linked-list/ListNode.ts"; export default function removeNthFromEnd( head: ListNode | null, - n: number + n: number, ): ListNode | null { if (!head) return head; const nodes: ListNode[] = []; diff --git a/remove-zero-sum-consecutive-nodes-from-linked-list/index.ts b/remove-zero-sum-consecutive-nodes-from-linked-list/index.ts index 25b56053..98138738 100644 --- a/remove-zero-sum-consecutive-nodes-from-linked-list/index.ts +++ b/remove-zero-sum-consecutive-nodes-from-linked-list/index.ts @@ -1,7 +1,7 @@ import { ListNode } from "../mod.ts"; export default function removeZeroSumSublists( - head: ListNode | null + head: ListNode | null, ): ListNode | null { const dummy = new ListNode(0, head); diff --git a/replace-all-digits-with-characters/index.ts b/replace-all-digits-with-characters/index.ts index c4487c52..c9545cac 100644 --- a/replace-all-digits-with-characters/index.ts +++ b/replace-all-digits-with-characters/index.ts @@ -1,7 +1,11 @@ export default function replaceDigits(s: string): string { return Array.prototype.map - .call(s, (c, i, a) => - i & 1 ? String.fromCharCode(Number(c) + a[i - 1].charCodeAt(0)) : c + .call( + s, + (c, i, a) => + i & 1 + ? String.fromCharCode(Number(c) + a[i - 1].charCodeAt(0)) + : c, ) .join(""); } diff --git a/replace-all-s-to-avoid-consecutive-repeating-characters/index.ts b/replace-all-s-to-avoid-consecutive-repeating-characters/index.ts index cd792bf1..158ac6e1 100644 --- a/replace-all-s-to-avoid-consecutive-repeating-characters/index.ts +++ b/replace-all-s-to-avoid-consecutive-repeating-characters/index.ts @@ -1,17 +1,15 @@ export default function modifyString(s: string): string { return s.includes("?") ? modifyString( - Array.prototype.map - .call(s, (c, i, a) => - c === "?" - ? a[i + 1] === "?" - ? c - : ["a", "b", "c"].filter( - (v) => v !== a[i + 1] && v !== a[i - 1] - )[0] - : c - ) - .join("") - ) + Array.prototype.map + .call(s, (c, i, a) => + c === "?" + ? a[i + 1] === "?" ? c : ["a", "b", "c"].filter( + (v) => + v !== a[i + 1] && v !== a[i - 1], + )[0] + : c) + .join(""), + ) : s; } diff --git a/replace-words/index.ts b/replace-words/index.ts index a8a9f800..3b235216 100644 --- a/replace-words/index.ts +++ b/replace-words/index.ts @@ -3,7 +3,7 @@ import { PrefixTreeInsert, PrefixTreeSearchPrefix } from "../mod.ts"; export default function replaceWords( dictionary: string[], - sentence: string + sentence: string, ): string { const root = PrefixTree(); dictionary.forEach((word) => diff --git a/reshape-the-matrix/index.ts b/reshape-the-matrix/index.ts index 6b6edc46..859085e0 100644 --- a/reshape-the-matrix/index.ts +++ b/reshape-the-matrix/index.ts @@ -1,7 +1,7 @@ export default function matrixReshape( mat: number[][], r: number, - c: number + c: number, ): number[][] { if (r * c !== mat.length * mat[0].length) return mat; const arr = mat.flat(); diff --git a/reverse-linked-list-ii/index.ts b/reverse-linked-list-ii/index.ts index 968a9d77..281cf505 100644 --- a/reverse-linked-list-ii/index.ts +++ b/reverse-linked-list-ii/index.ts @@ -6,7 +6,7 @@ import { get_length_of_list } from "./get_length_of_list.ts"; export default function reverseBetween( head: ListNode | null, left: number, - right: number + right: number, ): ListNode | null { if (!head) return head; if (!head.next) return head; @@ -20,7 +20,7 @@ export default function reverseBetween( if (left !== 1) { return new ListNode( head.val, - reverseBetween(head.next, left - 1, right - 1) + reverseBetween(head.next, left - 1, right - 1), ); } const start = get_deep_next_of_list(head, left - 1); diff --git a/reverse-linked-list/index.ts b/reverse-linked-list/index.ts index 8ef69ec2..8d86e698 100644 --- a/reverse-linked-list/index.ts +++ b/reverse-linked-list/index.ts @@ -1,7 +1,7 @@ import { ListNode } from "./ListNode.ts"; export default function reverse_Linked_List( - head: ListNode | null + head: ListNode | null, ): ListNode | null { let ans = null; let x = head; diff --git a/reverse-words-in-a-string-ii/index.ts b/reverse-words-in-a-string-ii/index.ts index 21afb829..74cbfb98 100644 --- a/reverse-words-in-a-string-ii/index.ts +++ b/reverse-words-in-a-string-ii/index.ts @@ -1,6 +1,6 @@ export default function reverseWords(s: string[]): void { Array.prototype.forEach.call( s.join("").trim().split(/\s+/g).reverse().join(" "), - (v, i) => (s[i] = v) + (v, i) => (s[i] = v), ); } diff --git a/rotate-array/index.ts b/rotate-array/index.ts index d3df6925..4afb0a0e 100644 --- a/rotate-array/index.ts +++ b/rotate-array/index.ts @@ -2,7 +2,7 @@ export default function rotate(nums: number[], k: number): void { [...nums, ...nums] .slice( nums.length - (k % nums.length), - 2 * nums.length - (k % nums.length) + 2 * nums.length - (k % nums.length), ) .forEach((v, i) => (nums[i] = v)); } diff --git a/same-tree/index.ts b/same-tree/index.ts index 5ba23dcf..ec4fdc86 100644 --- a/same-tree/index.ts +++ b/same-tree/index.ts @@ -2,11 +2,9 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function isSameTree( p: TreeNode | null | undefined, - q: TreeNode | null | undefined + q: TreeNode | null | undefined, ): boolean { - return p === q - ? true - : p?.val === q?.val && - isSameTree(p?.left, q?.left) && - isSameTree(p?.right, q?.right); + return p === q ? true : p?.val === q?.val && + isSameTree(p?.left, q?.left) && + isSameTree(p?.right, q?.right); } diff --git a/score-of-parentheses/index.ts b/score-of-parentheses/index.ts index e9334e4d..51c586eb 100644 --- a/score-of-parentheses/index.ts +++ b/score-of-parentheses/index.ts @@ -6,8 +6,8 @@ function scoreOfParentheses(s: string): number { `[${s}]` .replaceAll(")(", "],[") .replaceAll("(", "[") - .replaceAll(")", "]") - ) + .replaceAll(")", "]"), + ), ) / 2 ); } diff --git a/scramble-string/index.ts b/scramble-string/index.ts index 4e46bde2..582ad839 100644 --- a/scramble-string/index.ts +++ b/scramble-string/index.ts @@ -2,12 +2,11 @@ export default isScramble; function isScramble( s1: string, s2: string, - cache = new Map() + cache = new Map(), ): boolean { if (cache.has(s1 + s2)) return Boolean(cache.get(s1 + s2)); - const res = - s1 === s2 || + const res = s1 === s2 || ([...s1].sort().join("") === [...s2].sort().join("") && Array(s1.length - 1) .fill(0) @@ -16,23 +15,23 @@ function isScramble( (isScramble( s1.slice(0, i + 1), s2.slice(0, i + 1), - cache + cache, ) && isScramble( s1.slice(i + 1), s2.slice(i + 1), - cache + cache, )) || (isScramble( s1.slice(0, i + 1), s2.slice(-(i + 1)), - cache + cache, ) && isScramble( s1.slice(i + 1), s2.slice(0, -(i + 1)), - cache - )) + cache, + )), )); cache.set(s1 + s2, res); diff --git a/search-a-2d-matrix/index.ts b/search-a-2d-matrix/index.ts index 68a0663f..2b2cff11 100644 --- a/search-a-2d-matrix/index.ts +++ b/search-a-2d-matrix/index.ts @@ -2,7 +2,7 @@ import search from "../binary-search/index.ts"; export default function searchMatrix( matrix: number[][], - target: number + target: number, ): boolean { const index = search(matrix.flat(), target); return index >= 0 ? true : false; diff --git a/search-in-a-binary-search-tree/index.ts b/search-in-a-binary-search-tree/index.ts index 11107316..4b024437 100644 --- a/search-in-a-binary-search-tree/index.ts +++ b/search-in-a-binary-search-tree/index.ts @@ -2,7 +2,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; export default function searchBST( root: TreeNode | null, - val: number + val: number, ): TreeNode | null | undefined { if (!root) return null; if (root.val > val) { diff --git a/second-largest-digit-in-a-string/index.ts b/second-largest-digit-in-a-string/index.ts index 30dee827..96ed0bc0 100644 --- a/second-largest-digit-in-a-string/index.ts +++ b/second-largest-digit-in-a-string/index.ts @@ -1,7 +1,7 @@ function secondHighest(s: string): number { return Number( [...new Set(s.match(/[\d]/g))].sort((a, b) => b.localeCompare(a))[1] || - -1 + -1, ); } export default secondHighest; diff --git a/serialize-and-deserialize-binary-tree/index.ts b/serialize-and-deserialize-binary-tree/index.ts index 25c031cf..7554839a 100644 --- a/serialize-and-deserialize-binary-tree/index.ts +++ b/serialize-and-deserialize-binary-tree/index.ts @@ -29,7 +29,7 @@ function ArrayToTreeNode(array: TreeNodeArray): TreeNode | null { return new TreeNode( array[0], ArrayToTreeNode(array[1]), - ArrayToTreeNode(array[2]) + ArrayToTreeNode(array[2]), ); } if (Array.isArray(array) && array.length === 2) { @@ -45,7 +45,7 @@ export function deserialize(data: string): TreeNode | null { return null; } const array = JSON.parse( - data.replaceAll(",,", ",null,") + data.replaceAll(",,", ",null,"), // .replaceAll(",]", ",null]"), ); return ArrayToTreeNode(array); diff --git a/serialize-and-deserialize-n-ary-tree/index.ts b/serialize-and-deserialize-n-ary-tree/index.ts index 4d3e3594..6324d7ee 100644 --- a/serialize-and-deserialize-n-ary-tree/index.ts +++ b/serialize-and-deserialize-n-ary-tree/index.ts @@ -5,7 +5,7 @@ export function serialize(root: Node | null): string { } export function deserialize(data: string): Node | null { return ArrayToNAryNode( - JSON.parse(data.replaceAll(",,", ",null,").replaceAll("[,", "[null,")) + JSON.parse(data.replaceAll(",,", ",null,").replaceAll("[,", "[null,")), ); } function NAryNodeToArray(root: Node | null): (number[] | null)[][] { diff --git a/shift-2d-grid/index.ts b/shift-2d-grid/index.ts index c06372af..2024c590 100644 --- a/shift-2d-grid/index.ts +++ b/shift-2d-grid/index.ts @@ -7,9 +7,10 @@ export default function shiftGrid(grid: number[][], k: number): number[][] { grid .flat() .map( - (_, i, a) => a[(100 * a.length + a.length + (i - k)) % a.length] + (_, i, a) => + a[(100 * a.length + a.length + (i - k)) % a.length], ), m, - n + n, ); } diff --git a/shortest-bridge/index.ts b/shortest-bridge/index.ts index e04b7669..0b0b4f3d 100644 --- a/shortest-bridge/index.ts +++ b/shortest-bridge/index.ts @@ -7,7 +7,8 @@ export default function shortestBridge(grid: number[][]): number { ]; let firstIsland: [number, number][] = []; - loop: for (const [i, a] of grid.entries()) { + loop: + for (const [i, a] of grid.entries()) { for (const [j, v] of a.entries()) { if (v === 1) { firstIsland.push([i, j]); diff --git a/shortest-distance-to-target-string-in-a-circular-array/index.ts b/shortest-distance-to-target-string-in-a-circular-array/index.ts index 2b5346fc..ceca1b96 100644 --- a/shortest-distance-to-target-string-in-a-circular-array/index.ts +++ b/shortest-distance-to-target-string-in-a-circular-array/index.ts @@ -1,7 +1,7 @@ function closetTarget( words: string[], target: string, - startIndex: number + startIndex: number, ): number { if (!words.includes(target)) return -1; @@ -15,7 +15,7 @@ function closetTarget( return Math.min( ...indexes.map((index) => Math.abs(index - startIndex)), ...indexes.map((index) => Math.abs(words.length + index - startIndex)), - ...indexes.map((index) => Math.abs(-words.length + index - startIndex)) + ...indexes.map((index) => Math.abs(-words.length + index - startIndex)), ); } export default closetTarget; diff --git a/shortest-path-in-a-hidden-grid/index.ts b/shortest-path-in-a-hidden-grid/index.ts index f75a37db..ead335bf 100644 --- a/shortest-path-in-a-hidden-grid/index.ts +++ b/shortest-path-in-a-hidden-grid/index.ts @@ -34,7 +34,7 @@ export default function findShortestPath(master: GridMaster): number { function bfs( pos: [number, number][], distance: number, - visited: Set + visited: Set, ): number { const temp: [number, number][] = []; for (const [row, col] of pos) { diff --git a/shortest-word-distance-iii/index.ts b/shortest-word-distance-iii/index.ts index 73c6018d..efdc6a53 100644 --- a/shortest-word-distance-iii/index.ts +++ b/shortest-word-distance-iii/index.ts @@ -1,7 +1,7 @@ export default function shortestDistance( words: string[], word1: string, - word2: string + word2: string, ): number { let posA = -1; let posB = -1; diff --git a/shortest-word-distance/index.ts b/shortest-word-distance/index.ts index 9580040c..1f2b8a85 100644 --- a/shortest-word-distance/index.ts +++ b/shortest-word-distance/index.ts @@ -1,7 +1,7 @@ export default function shortestDistance( words: string[], word1: string, - word2: string + word2: string, ): number { const pos = new Map(); diff --git a/shu-de-zi-jie-gou-lcof/index.ts b/shu-de-zi-jie-gou-lcof/index.ts index ba32a181..b550bb38 100644 --- a/shu-de-zi-jie-gou-lcof/index.ts +++ b/shu-de-zi-jie-gou-lcof/index.ts @@ -6,7 +6,7 @@ function isSubStructure(A: TreeNode | null, B: TreeNode | null): boolean { B && (helper(A, B) || isSubStructure(A.left, B) || - isSubStructure(A.right, B)) + isSubStructure(A.right, B)), ); } export default isSubStructure; diff --git a/single-threaded-cpu/index.ts b/single-threaded-cpu/index.ts index d94e5bc4..8e87edba 100644 --- a/single-threaded-cpu/index.ts +++ b/single-threaded-cpu/index.ts @@ -6,7 +6,7 @@ export default function getOrder(tasks: number[][]): number[] { index, processingTime, enqueueTime, - }) + }), ); tasks_indexed.sort((a, b) => -a.enqueueTime + b.enqueueTime); @@ -26,7 +26,7 @@ export default function getOrder(tasks: number[][]): number[] { if (pq.isEmpty()) { time = Math.max( time, - tasks_indexed[tasks_indexed.length - 1].enqueueTime + tasks_indexed[tasks_indexed.length - 1].enqueueTime, ); } diff --git a/smallest-difference-lcci/index.ts b/smallest-difference-lcci/index.ts index 7c795500..bf8676da 100644 --- a/smallest-difference-lcci/index.ts +++ b/smallest-difference-lcci/index.ts @@ -10,8 +10,8 @@ export default function smallestDifference(a: number[], b: number[]): number { p, i === 0 || v[1] === a[i - 1][1] ? 2147483647 - : Math.abs(v[0] - a[i - 1][0]) + : Math.abs(v[0] - a[i - 1][0]), ), - 2147483647 + 2147483647, ); } diff --git a/smallest-subtree-with-all-the-deepest-nodes/index.ts b/smallest-subtree-with-all-the-deepest-nodes/index.ts index b4604bd9..a166e311 100644 --- a/smallest-subtree-with-all-the-deepest-nodes/index.ts +++ b/smallest-subtree-with-all-the-deepest-nodes/index.ts @@ -2,7 +2,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; import maxDepth from "../maximum-depth-of-binary-tree/index.ts"; export default function subtreeWithAllDeepest( - root: TreeNode | null + root: TreeNode | null, ): TreeNode | null { if (root == null) { return null; diff --git a/solve-the-equation/index.ts b/solve-the-equation/index.ts index a8629dff..d6f0d7c3 100644 --- a/solve-the-equation/index.ts +++ b/solve-the-equation/index.ts @@ -24,12 +24,10 @@ function parse_equation(equation: string) { const nl = el.filter((g) => g?.b).map((g) => g?.b); const nr = er.filter((g) => g?.b).map((g) => g?.b); //console.log(cl,cr,nl,nr) - const bodya = - "return " + + const bodya = "return " + (cl.length ? cl.join(" ") : "0 ") + `-(${cr.length ? cr.join(" ") : "0"})`; - const bodyb = - "return " + + const bodyb = "return " + (nr.length ? nr.join(" ") : " 0 ") + `-(${nl.length ? nl.join(" ") : " 0 "})`; diff --git a/sort-an-array/index.ts b/sort-an-array/index.ts index 18c447d9..3537e5e3 100644 --- a/sort-an-array/index.ts +++ b/sort-an-array/index.ts @@ -21,7 +21,7 @@ function mergeArray( left1: number, right1: number, left2: number, - right2: number + right2: number, ) { const temp: number[] = Array(right2 - left2 + right1 - left1 + 2); diff --git a/sort-array-by-parity/index.ts b/sort-array-by-parity/index.ts index 1cd9836c..86d5e2d1 100644 --- a/sort-array-by-parity/index.ts +++ b/sort-array-by-parity/index.ts @@ -2,6 +2,6 @@ import { groupBy } from "../deps.ts"; export default function sortArrayByParity(nums: number[]): number[] { return Object.values( - groupBy(nums, (a) => Number(a % 2)) + groupBy(nums, (a) => Number(a % 2)), ).flat() as number[]; } diff --git a/sort-characters-by-frequency/index.ts b/sort-characters-by-frequency/index.ts index 11bcb0b3..d4223e3b 100644 --- a/sort-characters-by-frequency/index.ts +++ b/sort-characters-by-frequency/index.ts @@ -4,9 +4,11 @@ export default function frequencySort(s: string): string { storage.set(w, 1 + (storage.get(w) ?? 0)); } const sb: string[] = []; - for (const [c, frequency] of [...storage.entries()].sort((a, b) => { - return +b[1] - a[1]; - })) { + for ( + const [c, frequency] of [...storage.entries()].sort((a, b) => { + return +b[1] - a[1]; + }) + ) { for (let j = 0; j < frequency; j++) { sb.push(c); } diff --git a/sort-the-people/index.ts b/sort-the-people/index.ts index 6754243e..34cb9046 100644 --- a/sort-the-people/index.ts +++ b/sort-the-people/index.ts @@ -1,6 +1,6 @@ export default function sortPeople( names: string[], - heights: number[] + heights: number[], ): string[] { return [...names.entries()] .sort((a, b) => -(heights[a[0]] ?? 0) + (heights[b[0]] ?? 0)) diff --git a/soup-servings/index.ts b/soup-servings/index.ts index 5373608b..d8b69cbd 100644 --- a/soup-servings/index.ts +++ b/soup-servings/index.ts @@ -23,7 +23,7 @@ export default function soupServings(n: number): number { dfs(a - 1, b - 3)) ); }, - (a: number, b: number) => JSON.stringify([a, b]) + (a: number, b: number) => JSON.stringify([a, b]), ); return dfs(n, n); } diff --git a/special-binary-string/index.ts b/special-binary-string/index.ts index e39cba24..2c97c450 100644 --- a/special-binary-string/index.ts +++ b/special-binary-string/index.ts @@ -4,7 +4,7 @@ export default function makeLargestSpecial(s: string): string { cur += s[i] === "1" ? 1 : -1; if (cur == 0) { candidates.push( - "1" + makeLargestSpecial(s.substring(last + 1, i)) + "0" + "1" + makeLargestSpecial(s.substring(last + 1, i)) + "0", ); last = i + 1; } diff --git a/special-positions-in-a-binary-matrix/index.ts b/special-positions-in-a-binary-matrix/index.ts index f355e0d8..c492b734 100644 --- a/special-positions-in-a-binary-matrix/index.ts +++ b/special-positions-in-a-binary-matrix/index.ts @@ -8,7 +8,7 @@ function numSpecial(mat: number[][]): number { mat.forEach( (a, i) => rowsum[i] === 1 && - a.forEach((v, j) => (ans += Number(v === 1 && colsum[j] === 1))) + a.forEach((v, j) => (ans += Number(v === 1 && colsum[j] === 1))), ); return ans; diff --git a/spiral-matrix-ii/index.ts b/spiral-matrix-ii/index.ts index ff460c76..ecb8b1cf 100644 --- a/spiral-matrix-ii/index.ts +++ b/spiral-matrix-ii/index.ts @@ -163,48 +163,191 @@ export default function generateMatrix(n: number): number[][] { [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 16], [ - 55, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, - 70, 17, - ], - [ - 54, 103, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 116, - 71, 18, - ], - [ - 53, 102, 143, 176, 177, 178, 179, 180, 181, 182, 183, 154, 117, - 72, 19, - ], - [ - 52, 101, 142, 175, 200, 201, 202, 203, 204, 205, 184, 155, 118, - 73, 20, - ], - [ - 51, 100, 141, 174, 199, 216, 217, 218, 219, 206, 185, 156, 119, - 74, 21, - ], - [ - 50, 99, 140, 173, 198, 215, 224, 225, 220, 207, 186, 157, 120, - 75, 22, - ], - [ - 49, 98, 139, 172, 197, 214, 223, 222, 221, 208, 187, 158, 121, - 76, 23, - ], - [ - 48, 97, 138, 171, 196, 213, 212, 211, 210, 209, 188, 159, 122, - 77, 24, - ], - [ - 47, 96, 137, 170, 195, 194, 193, 192, 191, 190, 189, 160, 123, - 78, 25, - ], - [ - 46, 95, 136, 169, 168, 167, 166, 165, 164, 163, 162, 161, 124, - 79, 26, + 55, + 104, + 105, + 106, + 107, + 108, + 109, + 110, + 111, + 112, + 113, + 114, + 115, + 70, + 17, + ], + [ + 54, + 103, + 144, + 145, + 146, + 147, + 148, + 149, + 150, + 151, + 152, + 153, + 116, + 71, + 18, ], [ - 45, 94, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, - 80, 27, + 53, + 102, + 143, + 176, + 177, + 178, + 179, + 180, + 181, + 182, + 183, + 154, + 117, + 72, + 19, + ], + [ + 52, + 101, + 142, + 175, + 200, + 201, + 202, + 203, + 204, + 205, + 184, + 155, + 118, + 73, + 20, + ], + [ + 51, + 100, + 141, + 174, + 199, + 216, + 217, + 218, + 219, + 206, + 185, + 156, + 119, + 74, + 21, + ], + [ + 50, + 99, + 140, + 173, + 198, + 215, + 224, + 225, + 220, + 207, + 186, + 157, + 120, + 75, + 22, + ], + [ + 49, + 98, + 139, + 172, + 197, + 214, + 223, + 222, + 221, + 208, + 187, + 158, + 121, + 76, + 23, + ], + [ + 48, + 97, + 138, + 171, + 196, + 213, + 212, + 211, + 210, + 209, + 188, + 159, + 122, + 77, + 24, + ], + [ + 47, + 96, + 137, + 170, + 195, + 194, + 193, + 192, + 191, + 190, + 189, + 160, + 123, + 78, + 25, + ], + [ + 46, + 95, + 136, + 169, + 168, + 167, + 166, + 165, + 164, + 163, + 162, + 161, + 124, + 79, + 26, + ], + [ + 45, + 94, + 135, + 134, + 133, + 132, + 131, + 130, + 129, + 128, + 127, + 126, + 125, + 80, + 27, ], [44, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 28], [43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29], @@ -215,52 +358,220 @@ export default function generateMatrix(n: number): number[][] { [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], [60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 17], [ - 59, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, - 124, 75, 18, - ], - [ - 58, 111, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, - 125, 76, 19, - ], - [ - 57, 110, 155, 192, 193, 194, 195, 196, 197, 198, 199, 200, 167, - 126, 77, 20, - ], - [ - 56, 109, 154, 191, 220, 221, 222, 223, 224, 225, 226, 201, 168, - 127, 78, 21, - ], - [ - 55, 108, 153, 190, 219, 240, 241, 242, 243, 244, 227, 202, 169, - 128, 79, 22, - ], - [ - 54, 107, 152, 189, 218, 239, 252, 253, 254, 245, 228, 203, 170, - 129, 80, 23, - ], - [ - 53, 106, 151, 188, 217, 238, 251, 256, 255, 246, 229, 204, 171, - 130, 81, 24, - ], - [ - 52, 105, 150, 187, 216, 237, 250, 249, 248, 247, 230, 205, 172, - 131, 82, 25, - ], - [ - 51, 104, 149, 186, 215, 236, 235, 234, 233, 232, 231, 206, 173, - 132, 83, 26, - ], - [ - 50, 103, 148, 185, 214, 213, 212, 211, 210, 209, 208, 207, 174, - 133, 84, 27, - ], - [ - 49, 102, 147, 184, 183, 182, 181, 180, 179, 178, 177, 176, 175, - 134, 85, 28, + 59, + 112, + 113, + 114, + 115, + 116, + 117, + 118, + 119, + 120, + 121, + 122, + 123, + 124, + 75, + 18, ], [ - 48, 101, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, - 135, 86, 29, + 58, + 111, + 156, + 157, + 158, + 159, + 160, + 161, + 162, + 163, + 164, + 165, + 166, + 125, + 76, + 19, + ], + [ + 57, + 110, + 155, + 192, + 193, + 194, + 195, + 196, + 197, + 198, + 199, + 200, + 167, + 126, + 77, + 20, + ], + [ + 56, + 109, + 154, + 191, + 220, + 221, + 222, + 223, + 224, + 225, + 226, + 201, + 168, + 127, + 78, + 21, + ], + [ + 55, + 108, + 153, + 190, + 219, + 240, + 241, + 242, + 243, + 244, + 227, + 202, + 169, + 128, + 79, + 22, + ], + [ + 54, + 107, + 152, + 189, + 218, + 239, + 252, + 253, + 254, + 245, + 228, + 203, + 170, + 129, + 80, + 23, + ], + [ + 53, + 106, + 151, + 188, + 217, + 238, + 251, + 256, + 255, + 246, + 229, + 204, + 171, + 130, + 81, + 24, + ], + [ + 52, + 105, + 150, + 187, + 216, + 237, + 250, + 249, + 248, + 247, + 230, + 205, + 172, + 131, + 82, + 25, + ], + [ + 51, + 104, + 149, + 186, + 215, + 236, + 235, + 234, + 233, + 232, + 231, + 206, + 173, + 132, + 83, + 26, + ], + [ + 50, + 103, + 148, + 185, + 214, + 213, + 212, + 211, + 210, + 209, + 208, + 207, + 174, + 133, + 84, + 27, + ], + [ + 49, + 102, + 147, + 184, + 183, + 182, + 181, + 180, + 179, + 178, + 177, + 176, + 175, + 134, + 85, + 28, + ], + [ + 48, + 101, + 146, + 145, + 144, + 143, + 142, + 141, + 140, + 139, + 138, + 137, + 136, + 135, + 86, + 29, ], [47, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 30], [46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31], @@ -270,67 +581,307 @@ export default function generateMatrix(n: number): number[][] { return [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], [ - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, + 64, + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72, + 73, + 74, + 75, + 76, + 77, + 78, + 79, 18, ], [ - 63, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, - 132, 133, 80, 19, - ], - [ - 62, 119, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, - 179, 134, 81, 20, - ], - [ - 61, 118, 167, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, - 180, 135, 82, 21, - ], - [ - 60, 117, 166, 207, 240, 241, 242, 243, 244, 245, 246, 247, 218, - 181, 136, 83, 22, - ], - [ - 59, 116, 165, 206, 239, 264, 265, 266, 267, 268, 269, 248, 219, - 182, 137, 84, 23, - ], - [ - 58, 115, 164, 205, 238, 263, 280, 281, 282, 283, 270, 249, 220, - 183, 138, 85, 24, - ], - [ - 57, 114, 163, 204, 237, 262, 279, 288, 289, 284, 271, 250, 221, - 184, 139, 86, 25, - ], - [ - 56, 113, 162, 203, 236, 261, 278, 287, 286, 285, 272, 251, 222, - 185, 140, 87, 26, - ], - [ - 55, 112, 161, 202, 235, 260, 277, 276, 275, 274, 273, 252, 223, - 186, 141, 88, 27, - ], - [ - 54, 111, 160, 201, 234, 259, 258, 257, 256, 255, 254, 253, 224, - 187, 142, 89, 28, - ], - [ - 53, 110, 159, 200, 233, 232, 231, 230, 229, 228, 227, 226, 225, - 188, 143, 90, 29, - ], - [ - 52, 109, 158, 199, 198, 197, 196, 195, 194, 193, 192, 191, 190, - 189, 144, 91, 30, - ], - [ - 51, 108, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, - 146, 145, 92, 31, - ], - [ - 50, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, - 94, 93, 32, - ], - [ - 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, + 63, + 120, + 121, + 122, + 123, + 124, + 125, + 126, + 127, + 128, + 129, + 130, + 131, + 132, + 133, + 80, + 19, + ], + [ + 62, + 119, + 168, + 169, + 170, + 171, + 172, + 173, + 174, + 175, + 176, + 177, + 178, + 179, + 134, + 81, + 20, + ], + [ + 61, + 118, + 167, + 208, + 209, + 210, + 211, + 212, + 213, + 214, + 215, + 216, + 217, + 180, + 135, + 82, + 21, + ], + [ + 60, + 117, + 166, + 207, + 240, + 241, + 242, + 243, + 244, + 245, + 246, + 247, + 218, + 181, + 136, + 83, + 22, + ], + [ + 59, + 116, + 165, + 206, + 239, + 264, + 265, + 266, + 267, + 268, + 269, + 248, + 219, + 182, + 137, + 84, + 23, + ], + [ + 58, + 115, + 164, + 205, + 238, + 263, + 280, + 281, + 282, + 283, + 270, + 249, + 220, + 183, + 138, + 85, + 24, + ], + [ + 57, + 114, + 163, + 204, + 237, + 262, + 279, + 288, + 289, + 284, + 271, + 250, + 221, + 184, + 139, + 86, + 25, + ], + [ + 56, + 113, + 162, + 203, + 236, + 261, + 278, + 287, + 286, + 285, + 272, + 251, + 222, + 185, + 140, + 87, + 26, + ], + [ + 55, + 112, + 161, + 202, + 235, + 260, + 277, + 276, + 275, + 274, + 273, + 252, + 223, + 186, + 141, + 88, + 27, + ], + [ + 54, + 111, + 160, + 201, + 234, + 259, + 258, + 257, + 256, + 255, + 254, + 253, + 224, + 187, + 142, + 89, + 28, + ], + [ + 53, + 110, + 159, + 200, + 233, + 232, + 231, + 230, + 229, + 228, + 227, + 226, + 225, + 188, + 143, + 90, + 29, + ], + [ + 52, + 109, + 158, + 199, + 198, + 197, + 196, + 195, + 194, + 193, + 192, + 191, + 190, + 189, + 144, + 91, + 30, + ], + [ + 51, + 108, + 157, + 156, + 155, + 154, + 153, + 152, + 151, + 150, + 149, + 148, + 147, + 146, + 145, + 92, + 31, + ], + [ + 50, + 107, + 106, + 105, + 104, + 103, + 102, + 101, + 100, + 99, + 98, + 97, + 96, + 95, + 94, + 93, + 32, + ], + [ + 49, + 48, + 47, + 46, + 45, + 44, + 43, + 42, + 41, + 40, + 39, + 38, + 37, + 36, + 35, + 34, 33, ], ]; @@ -339,72 +890,344 @@ export default function generateMatrix(n: number): number[][] { return [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], [ - 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, - 84, 19, - ], - [ - 67, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, - 140, 141, 142, 85, 20, - ], - [ - 66, 127, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, - 191, 192, 143, 86, 21, - ], - [ - 65, 126, 179, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, - 234, 193, 144, 87, 22, - ], - [ - 64, 125, 178, 223, 260, 261, 262, 263, 264, 265, 266, 267, 268, - 235, 194, 145, 88, 23, - ], - [ - 63, 124, 177, 222, 259, 288, 289, 290, 291, 292, 293, 294, 269, - 236, 195, 146, 89, 24, - ], - [ - 62, 123, 176, 221, 258, 287, 308, 309, 310, 311, 312, 295, 270, - 237, 196, 147, 90, 25, - ], - [ - 61, 122, 175, 220, 257, 286, 307, 320, 321, 322, 313, 296, 271, - 238, 197, 148, 91, 26, - ], - [ - 60, 121, 174, 219, 256, 285, 306, 319, 324, 323, 314, 297, 272, - 239, 198, 149, 92, 27, - ], - [ - 59, 120, 173, 218, 255, 284, 305, 318, 317, 316, 315, 298, 273, - 240, 199, 150, 93, 28, - ], - [ - 58, 119, 172, 217, 254, 283, 304, 303, 302, 301, 300, 299, 274, - 241, 200, 151, 94, 29, - ], - [ - 57, 118, 171, 216, 253, 282, 281, 280, 279, 278, 277, 276, 275, - 242, 201, 152, 95, 30, - ], - [ - 56, 117, 170, 215, 252, 251, 250, 249, 248, 247, 246, 245, 244, - 243, 202, 153, 96, 31, - ], - [ - 55, 116, 169, 214, 213, 212, 211, 210, 209, 208, 207, 206, 205, - 204, 203, 154, 97, 32, - ], - [ - 54, 115, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158, - 157, 156, 155, 98, 33, - ], - [ - 53, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, - 102, 101, 100, 99, 34, + 68, + 69, + 70, + 71, + 72, + 73, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 81, + 82, + 83, + 84, + 19, + ], + [ + 67, + 128, + 129, + 130, + 131, + 132, + 133, + 134, + 135, + 136, + 137, + 138, + 139, + 140, + 141, + 142, + 85, + 20, + ], + [ + 66, + 127, + 180, + 181, + 182, + 183, + 184, + 185, + 186, + 187, + 188, + 189, + 190, + 191, + 192, + 143, + 86, + 21, + ], + [ + 65, + 126, + 179, + 224, + 225, + 226, + 227, + 228, + 229, + 230, + 231, + 232, + 233, + 234, + 193, + 144, + 87, + 22, + ], + [ + 64, + 125, + 178, + 223, + 260, + 261, + 262, + 263, + 264, + 265, + 266, + 267, + 268, + 235, + 194, + 145, + 88, + 23, + ], + [ + 63, + 124, + 177, + 222, + 259, + 288, + 289, + 290, + 291, + 292, + 293, + 294, + 269, + 236, + 195, + 146, + 89, + 24, + ], + [ + 62, + 123, + 176, + 221, + 258, + 287, + 308, + 309, + 310, + 311, + 312, + 295, + 270, + 237, + 196, + 147, + 90, + 25, + ], + [ + 61, + 122, + 175, + 220, + 257, + 286, + 307, + 320, + 321, + 322, + 313, + 296, + 271, + 238, + 197, + 148, + 91, + 26, + ], + [ + 60, + 121, + 174, + 219, + 256, + 285, + 306, + 319, + 324, + 323, + 314, + 297, + 272, + 239, + 198, + 149, + 92, + 27, + ], + [ + 59, + 120, + 173, + 218, + 255, + 284, + 305, + 318, + 317, + 316, + 315, + 298, + 273, + 240, + 199, + 150, + 93, + 28, + ], + [ + 58, + 119, + 172, + 217, + 254, + 283, + 304, + 303, + 302, + 301, + 300, + 299, + 274, + 241, + 200, + 151, + 94, + 29, + ], + [ + 57, + 118, + 171, + 216, + 253, + 282, + 281, + 280, + 279, + 278, + 277, + 276, + 275, + 242, + 201, + 152, + 95, + 30, + ], + [ + 56, + 117, + 170, + 215, + 252, + 251, + 250, + 249, + 248, + 247, + 246, + 245, + 244, + 243, + 202, + 153, + 96, + 31, + ], + [ + 55, + 116, + 169, + 214, + 213, + 212, + 211, + 210, + 209, + 208, + 207, + 206, + 205, + 204, + 203, + 154, + 97, + 32, + ], + [ + 54, + 115, + 168, + 167, + 166, + 165, + 164, + 163, + 162, + 161, + 160, + 159, + 158, + 157, + 156, + 155, + 98, + 33, ], [ - 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, - 36, 35, + 53, + 114, + 113, + 112, + 111, + 110, + 109, + 108, + 107, + 106, + 105, + 104, + 103, + 102, + 101, + 100, + 99, + 34, + ], + [ + 52, + 51, + 50, + 49, + 48, + 47, + 46, + 45, + 44, + 43, + 42, + 41, + 40, + 39, + 38, + 37, + 36, + 35, ], ]; } @@ -412,160 +1235,826 @@ export default function generateMatrix(n: number): number[][] { return [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [ - 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, - 88, 89, 20, - ], - [ - 71, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, - 148, 149, 150, 151, 90, 21, - ], - [ - 70, 135, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, - 203, 204, 205, 152, 91, 22, - ], - [ - 69, 134, 191, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, - 250, 251, 206, 153, 92, 23, - ], - [ - 68, 133, 190, 239, 280, 281, 282, 283, 284, 285, 286, 287, 288, - 289, 252, 207, 154, 93, 24, - ], - [ - 67, 132, 189, 238, 279, 312, 313, 314, 315, 316, 317, 318, 319, - 290, 253, 208, 155, 94, 25, - ], - [ - 66, 131, 188, 237, 278, 311, 336, 337, 338, 339, 340, 341, 320, - 291, 254, 209, 156, 95, 26, - ], - [ - 65, 130, 187, 236, 277, 310, 335, 352, 353, 354, 355, 342, 321, - 292, 255, 210, 157, 96, 27, - ], - [ - 64, 129, 186, 235, 276, 309, 334, 351, 360, 361, 356, 343, 322, - 293, 256, 211, 158, 97, 28, - ], - [ - 63, 128, 185, 234, 275, 308, 333, 350, 359, 358, 357, 344, 323, - 294, 257, 212, 159, 98, 29, - ], - [ - 62, 127, 184, 233, 274, 307, 332, 349, 348, 347, 346, 345, 324, - 295, 258, 213, 160, 99, 30, - ], - [ - 61, 126, 183, 232, 273, 306, 331, 330, 329, 328, 327, 326, 325, - 296, 259, 214, 161, 100, 31, - ], - [ - 60, 125, 182, 231, 272, 305, 304, 303, 302, 301, 300, 299, 298, - 297, 260, 215, 162, 101, 32, - ], - [ - 59, 124, 181, 230, 271, 270, 269, 268, 267, 266, 265, 264, 263, - 262, 261, 216, 163, 102, 33, - ], - [ - 58, 123, 180, 229, 228, 227, 226, 225, 224, 223, 222, 221, 220, - 219, 218, 217, 164, 103, 34, - ], - [ - 57, 122, 179, 178, 177, 176, 175, 174, 173, 172, 171, 170, 169, - 168, 167, 166, 165, 104, 35, - ], - [ - 56, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, - 109, 108, 107, 106, 105, 36, + 72, + 73, + 74, + 75, + 76, + 77, + 78, + 79, + 80, + 81, + 82, + 83, + 84, + 85, + 86, + 87, + 88, + 89, + 20, + ], + [ + 71, + 136, + 137, + 138, + 139, + 140, + 141, + 142, + 143, + 144, + 145, + 146, + 147, + 148, + 149, + 150, + 151, + 90, + 21, + ], + [ + 70, + 135, + 192, + 193, + 194, + 195, + 196, + 197, + 198, + 199, + 200, + 201, + 202, + 203, + 204, + 205, + 152, + 91, + 22, + ], + [ + 69, + 134, + 191, + 240, + 241, + 242, + 243, + 244, + 245, + 246, + 247, + 248, + 249, + 250, + 251, + 206, + 153, + 92, + 23, + ], + [ + 68, + 133, + 190, + 239, + 280, + 281, + 282, + 283, + 284, + 285, + 286, + 287, + 288, + 289, + 252, + 207, + 154, + 93, + 24, + ], + [ + 67, + 132, + 189, + 238, + 279, + 312, + 313, + 314, + 315, + 316, + 317, + 318, + 319, + 290, + 253, + 208, + 155, + 94, + 25, + ], + [ + 66, + 131, + 188, + 237, + 278, + 311, + 336, + 337, + 338, + 339, + 340, + 341, + 320, + 291, + 254, + 209, + 156, + 95, + 26, + ], + [ + 65, + 130, + 187, + 236, + 277, + 310, + 335, + 352, + 353, + 354, + 355, + 342, + 321, + 292, + 255, + 210, + 157, + 96, + 27, + ], + [ + 64, + 129, + 186, + 235, + 276, + 309, + 334, + 351, + 360, + 361, + 356, + 343, + 322, + 293, + 256, + 211, + 158, + 97, + 28, + ], + [ + 63, + 128, + 185, + 234, + 275, + 308, + 333, + 350, + 359, + 358, + 357, + 344, + 323, + 294, + 257, + 212, + 159, + 98, + 29, + ], + [ + 62, + 127, + 184, + 233, + 274, + 307, + 332, + 349, + 348, + 347, + 346, + 345, + 324, + 295, + 258, + 213, + 160, + 99, + 30, + ], + [ + 61, + 126, + 183, + 232, + 273, + 306, + 331, + 330, + 329, + 328, + 327, + 326, + 325, + 296, + 259, + 214, + 161, + 100, + 31, + ], + [ + 60, + 125, + 182, + 231, + 272, + 305, + 304, + 303, + 302, + 301, + 300, + 299, + 298, + 297, + 260, + 215, + 162, + 101, + 32, + ], + [ + 59, + 124, + 181, + 230, + 271, + 270, + 269, + 268, + 267, + 266, + 265, + 264, + 263, + 262, + 261, + 216, + 163, + 102, + 33, ], [ - 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, - 39, 38, 37, + 58, + 123, + 180, + 229, + 228, + 227, + 226, + 225, + 224, + 223, + 222, + 221, + 220, + 219, + 218, + 217, + 164, + 103, + 34, + ], + [ + 57, + 122, + 179, + 178, + 177, + 176, + 175, + 174, + 173, + 172, + 171, + 170, + 169, + 168, + 167, + 166, + 165, + 104, + 35, + ], + [ + 56, + 121, + 120, + 119, + 118, + 117, + 116, + 115, + 114, + 113, + 112, + 111, + 110, + 109, + 108, + 107, + 106, + 105, + 36, + ], + [ + 55, + 54, + 53, + 52, + 51, + 50, + 49, + 48, + 47, + 46, + 45, + 44, + 43, + 42, + 41, + 40, + 39, + 38, + 37, ], ]; } if (n == 20) { return [ [ - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - 19, 20, - ], - [ - 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, - 92, 93, 94, 21, - ], - [ - 75, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, - 156, 157, 158, 159, 160, 95, 22, - ], - [ - 74, 143, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, - 215, 216, 217, 218, 161, 96, 23, - ], - [ - 73, 142, 203, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, - 266, 267, 268, 219, 162, 97, 24, - ], - [ - 72, 141, 202, 255, 300, 301, 302, 303, 304, 305, 306, 307, 308, - 309, 310, 269, 220, 163, 98, 25, - ], - [ - 71, 140, 201, 254, 299, 336, 337, 338, 339, 340, 341, 342, 343, - 344, 311, 270, 221, 164, 99, 26, - ], - [ - 70, 139, 200, 253, 298, 335, 364, 365, 366, 367, 368, 369, 370, - 345, 312, 271, 222, 165, 100, 27, - ], - [ - 69, 138, 199, 252, 297, 334, 363, 384, 385, 386, 387, 388, 371, - 346, 313, 272, 223, 166, 101, 28, - ], - [ - 68, 137, 198, 251, 296, 333, 362, 383, 396, 397, 398, 389, 372, - 347, 314, 273, 224, 167, 102, 29, - ], - [ - 67, 136, 197, 250, 295, 332, 361, 382, 395, 400, 399, 390, 373, - 348, 315, 274, 225, 168, 103, 30, - ], - [ - 66, 135, 196, 249, 294, 331, 360, 381, 394, 393, 392, 391, 374, - 349, 316, 275, 226, 169, 104, 31, - ], - [ - 65, 134, 195, 248, 293, 330, 359, 380, 379, 378, 377, 376, 375, - 350, 317, 276, 227, 170, 105, 32, - ], - [ - 64, 133, 194, 247, 292, 329, 358, 357, 356, 355, 354, 353, 352, - 351, 318, 277, 228, 171, 106, 33, - ], - [ - 63, 132, 193, 246, 291, 328, 327, 326, 325, 324, 323, 322, 321, - 320, 319, 278, 229, 172, 107, 34, - ], - [ - 62, 131, 192, 245, 290, 289, 288, 287, 286, 285, 284, 283, 282, - 281, 280, 279, 230, 173, 108, 35, - ], - [ - 61, 130, 191, 244, 243, 242, 241, 240, 239, 238, 237, 236, 235, - 234, 233, 232, 231, 174, 109, 36, - ], - [ - 60, 129, 190, 189, 188, 187, 186, 185, 184, 183, 182, 181, 180, - 179, 178, 177, 176, 175, 110, 37, - ], - [ - 59, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, - 116, 115, 114, 113, 112, 111, 38, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + ], + [ + 76, + 77, + 78, + 79, + 80, + 81, + 82, + 83, + 84, + 85, + 86, + 87, + 88, + 89, + 90, + 91, + 92, + 93, + 94, + 21, + ], + [ + 75, + 144, + 145, + 146, + 147, + 148, + 149, + 150, + 151, + 152, + 153, + 154, + 155, + 156, + 157, + 158, + 159, + 160, + 95, + 22, + ], + [ + 74, + 143, + 204, + 205, + 206, + 207, + 208, + 209, + 210, + 211, + 212, + 213, + 214, + 215, + 216, + 217, + 218, + 161, + 96, + 23, + ], + [ + 73, + 142, + 203, + 256, + 257, + 258, + 259, + 260, + 261, + 262, + 263, + 264, + 265, + 266, + 267, + 268, + 219, + 162, + 97, + 24, + ], + [ + 72, + 141, + 202, + 255, + 300, + 301, + 302, + 303, + 304, + 305, + 306, + 307, + 308, + 309, + 310, + 269, + 220, + 163, + 98, + 25, + ], + [ + 71, + 140, + 201, + 254, + 299, + 336, + 337, + 338, + 339, + 340, + 341, + 342, + 343, + 344, + 311, + 270, + 221, + 164, + 99, + 26, + ], + [ + 70, + 139, + 200, + 253, + 298, + 335, + 364, + 365, + 366, + 367, + 368, + 369, + 370, + 345, + 312, + 271, + 222, + 165, + 100, + 27, + ], + [ + 69, + 138, + 199, + 252, + 297, + 334, + 363, + 384, + 385, + 386, + 387, + 388, + 371, + 346, + 313, + 272, + 223, + 166, + 101, + 28, + ], + [ + 68, + 137, + 198, + 251, + 296, + 333, + 362, + 383, + 396, + 397, + 398, + 389, + 372, + 347, + 314, + 273, + 224, + 167, + 102, + 29, + ], + [ + 67, + 136, + 197, + 250, + 295, + 332, + 361, + 382, + 395, + 400, + 399, + 390, + 373, + 348, + 315, + 274, + 225, + 168, + 103, + 30, + ], + [ + 66, + 135, + 196, + 249, + 294, + 331, + 360, + 381, + 394, + 393, + 392, + 391, + 374, + 349, + 316, + 275, + 226, + 169, + 104, + 31, + ], + [ + 65, + 134, + 195, + 248, + 293, + 330, + 359, + 380, + 379, + 378, + 377, + 376, + 375, + 350, + 317, + 276, + 227, + 170, + 105, + 32, + ], + [ + 64, + 133, + 194, + 247, + 292, + 329, + 358, + 357, + 356, + 355, + 354, + 353, + 352, + 351, + 318, + 277, + 228, + 171, + 106, + 33, ], [ - 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, - 42, 41, 40, 39, + 63, + 132, + 193, + 246, + 291, + 328, + 327, + 326, + 325, + 324, + 323, + 322, + 321, + 320, + 319, + 278, + 229, + 172, + 107, + 34, + ], + [ + 62, + 131, + 192, + 245, + 290, + 289, + 288, + 287, + 286, + 285, + 284, + 283, + 282, + 281, + 280, + 279, + 230, + 173, + 108, + 35, + ], + [ + 61, + 130, + 191, + 244, + 243, + 242, + 241, + 240, + 239, + 238, + 237, + 236, + 235, + 234, + 233, + 232, + 231, + 174, + 109, + 36, + ], + [ + 60, + 129, + 190, + 189, + 188, + 187, + 186, + 185, + 184, + 183, + 182, + 181, + 180, + 179, + 178, + 177, + 176, + 175, + 110, + 37, + ], + [ + 59, + 128, + 127, + 126, + 125, + 124, + 123, + 122, + 121, + 120, + 119, + 118, + 117, + 116, + 115, + 114, + 113, + 112, + 111, + 38, + ], + [ + 58, + 57, + 56, + 55, + 54, + 53, + 52, + 51, + 50, + 49, + 48, + 47, + 46, + 45, + 44, + 43, + 42, + 41, + 40, + 39, ], ]; } diff --git a/spiral-matrix-iv/index.ts b/spiral-matrix-iv/index.ts index 03f1e8e0..4ae1cbbd 100644 --- a/spiral-matrix-iv/index.ts +++ b/spiral-matrix-iv/index.ts @@ -4,7 +4,7 @@ import { ListNode } from "../reverse-linked-list/ListNode.ts"; export default function spiralMatrix( m: number, n: number, - head: ListNode | null + head: ListNode | null, ): number[][] { const si = spiralMatrixIterator(m, n); @@ -25,7 +25,7 @@ export default function spiralMatrix( } export function* spiralMatrixIterator( m: number, - n: number + n: number, ): Generator<[number, number], void, unknown> { let left = 0, right = n, diff --git a/split-linked-list-in-parts/index.ts b/split-linked-list-in-parts/index.ts index 96e99eee..dd8e0e1d 100644 --- a/split-linked-list-in-parts/index.ts +++ b/split-linked-list-in-parts/index.ts @@ -3,7 +3,7 @@ import { ListNode } from "../reverse-linked-list/ListNode.ts"; export default function splitListToParts( head: ListNode | null, - k: number + k: number, ): Array { if (!head || k === 0) { return Array(k).fill(null); diff --git a/split-message-based-on-limit/index.ts b/split-message-based-on-limit/index.ts index 67e6ca11..4519c1ab 100644 --- a/split-message-based-on-limit/index.ts +++ b/split-message-based-on-limit/index.ts @@ -1,6 +1,6 @@ export default function splitMessage(message: string, limit: number): string[] { const n = message.length; - for (let i = 1, cap = 0, tail_len = 0; ; ++i) { + for (let i = 1, cap = 0, tail_len = 0;; ++i) { if (i < 10) tail_len = 5; // 结尾的长度 else if (i < 100) { if (i == 10) cap -= 9; // 前面的结尾的长度都 +1,那么容量就要减小 diff --git a/student-attendance-record-ii/index.ts b/student-attendance-record-ii/index.ts index e30e1602..ae0999be 100644 --- a/student-attendance-record-ii/index.ts +++ b/student-attendance-record-ii/index.ts @@ -4,7 +4,7 @@ const maxnum = 10 ** 5; function checkRecord(n: number): number { if (dp.length === 0) { dp.push( - ...new Array(maxnum + 1).fill(0).map(() => new Array(6).fill(0)) + ...new Array(maxnum + 1).fill(0).map(() => new Array(6).fill(0)), ); dp.length = maxnum + 1; // 长度,A 的数量,结尾连续 L 的数量 diff --git a/subrectangle-queries/index.ts b/subrectangle-queries/index.ts index c75ce72b..6cc3527e 100644 --- a/subrectangle-queries/index.ts +++ b/subrectangle-queries/index.ts @@ -9,7 +9,7 @@ export default class SubrectangleQueries { col1: number, row2: number, col2: number, - newValue: number + newValue: number, ): void { for (let i = row1; i <= row2; i++) { for (let j = col1; j <= col2; j++) { diff --git a/substring-with-concatenation-of-all-words/index.ts b/substring-with-concatenation-of-all-words/index.ts index 591dfa77..752ee342 100644 --- a/substring-with-concatenation-of-all-words/index.ts +++ b/substring-with-concatenation-of-all-words/index.ts @@ -32,7 +32,7 @@ export default function findSubstring(s: string, words: string[]): number[] { } } return true; - } + }, // equal( // cnts, // counter( diff --git a/successor-lcci/index.ts b/successor-lcci/index.ts index d41ff391..427687a0 100644 --- a/successor-lcci/index.ts +++ b/successor-lcci/index.ts @@ -2,7 +2,7 @@ import { TreeNode } from "../binary-tree-inorder-traversal/TreeNode.ts"; function inorderSuccessor( root: TreeNode | null, - p: TreeNode | null + p: TreeNode | null, ): TreeNode | null { if (!root) { return null; diff --git a/sudoku-solver/index.ts b/sudoku-solver/index.ts index 1b314e59..2093cb67 100644 --- a/sudoku-solver/index.ts +++ b/sudoku-solver/index.ts @@ -48,7 +48,7 @@ function dfs( rows: Record[], columns: Record[], subboxes: Record[][], - board: string[][] + board: string[][], ): boolean { if (spaces.size === 0) { return true; @@ -63,7 +63,7 @@ function dfs( spaces_and_chars.push([row, column, chars] as [ number, number, - string[] + string[], ]); if (chars.length === 1) { break; @@ -111,7 +111,7 @@ function get_available_chars( column: number, rows: Record[], columns: Record[], - subboxes: Record[][] + subboxes: Record[][], ): Array { const array = Array.from({ length: 9 }).map((_v, i) => String(i + 1)); const charset = new Set(array); diff --git a/sum-lists-lcci/index.ts b/sum-lists-lcci/index.ts index 57f9f98c..a256c697 100644 --- a/sum-lists-lcci/index.ts +++ b/sum-lists-lcci/index.ts @@ -2,7 +2,7 @@ import { ListNode } from "../reverse-linked-list/ListNode.ts"; function addTwoNumbers( l1: ListNode | null, - l2: ListNode | null + l2: ListNode | null, ): ListNode | null { if (!l1) { return l2; diff --git a/sum-of-beauty-of-all-substrings/index.ts b/sum-of-beauty-of-all-substrings/index.ts index d7008342..9a5fa568 100644 --- a/sum-of-beauty-of-all-substrings/index.ts +++ b/sum-of-beauty-of-all-substrings/index.ts @@ -7,7 +7,7 @@ function beautySum(s: string): number { cnt[s[j].charCodeAt(0) - "a".charCodeAt(0)]++; maxFreq = Math.max( maxFreq, - cnt[s[j].charCodeAt(0) - "a".charCodeAt(0)] + cnt[s[j].charCodeAt(0) - "a".charCodeAt(0)], ); let minFreq = s.length; for (let k = 0; k < 26; k++) { diff --git a/sum-of-left-leaves/index.ts b/sum-of-left-leaves/index.ts index 6ac7522d..4ba1e93f 100644 --- a/sum-of-left-leaves/index.ts +++ b/sum-of-left-leaves/index.ts @@ -4,7 +4,8 @@ export default sumOfLeftLeaves; function sumOfLeftLeaves(root: TreeNode | null): number { if (!root) return 0; - const sum = - root.left && !root.left.left && !root.left.right ? root.left.val : 0; + const sum = root.left && !root.left.left && !root.left.right + ? root.left.val + : 0; return sum + sumOfLeftLeaves(root.left) + sumOfLeftLeaves(root.right); } diff --git a/sum-of-prefix-scores-of-strings/index.ts b/sum-of-prefix-scores-of-strings/index.ts index 4407e6c8..be855350 100644 --- a/sum-of-prefix-scores-of-strings/index.ts +++ b/sum-of-prefix-scores-of-strings/index.ts @@ -19,7 +19,7 @@ export default sumPrefixScores; function TrieNodeSum( root: TrieNode, word: string, - word2sum: Map + word2sum: Map, ): number { let sum = 0; let index = 0; diff --git a/sum-of-root-to-leaf-binary-numbers/index.ts b/sum-of-root-to-leaf-binary-numbers/index.ts index d445d528..62a01e3e 100644 --- a/sum-of-root-to-leaf-binary-numbers/index.ts +++ b/sum-of-root-to-leaf-binary-numbers/index.ts @@ -6,5 +6,5 @@ export default function sumRootToLeaf(root: TreeNode | null, sum = 0): number { : !root.left && !root.right ? sum * 2 + root.val : sumRootToLeaf(root.left, sum * 2 + root.val) + - sumRootToLeaf(root.right, sum * 2 + root.val); + sumRootToLeaf(root.right, sum * 2 + root.val); } diff --git a/sum-of-subarray-minimums/index.ts b/sum-of-subarray-minimums/index.ts index 42149e8c..0ec5eaaf 100644 --- a/sum-of-subarray-minimums/index.ts +++ b/sum-of-subarray-minimums/index.ts @@ -11,10 +11,9 @@ export default function sumSubarrayMins(arr: number[]): number { ) { monoStack.pop(); } - const k = - monoStack.length === 0 - ? i + 1 - : i - monoStack[monoStack.length - 1]; + const k = monoStack.length === 0 + ? i + 1 + : i - monoStack[monoStack.length - 1]; dp[i] = k * arr[i] + (monoStack.length === 0 ? 0 : dp[i - k]); ans = (ans + dp[i]) % MOD; monoStack.push(i); diff --git a/sum-of-total-strength-of-wizards/index.ts b/sum-of-total-strength-of-wizards/index.ts index 2dd86858..d309ba03 100644 --- a/sum-of-total-strength-of-wizards/index.ts +++ b/sum-of-total-strength-of-wizards/index.ts @@ -39,9 +39,8 @@ export default function totalStrength(strength: number[]): number { for (let i = 0; i < n; i++) { const l = left[i] + 1; const r = right[i] - 1; - const total = - (BigInt((i - l + 1) * (ss[r + 2] - ss[i + 1])) - - BigInt((r - i + 1) * (ss[i + 1] - ss[l]))) % + const total = (BigInt((i - l + 1) * (ss[r + 2] - ss[i + 1])) - + BigInt((r - i + 1) * (ss[i + 1] - ss[l]))) % BigMOD; ans = (ans + BigInt(strength[i]) * BigInt(total)) % BigMOD; } diff --git a/sum-root-to-leaf-numbers/index.ts b/sum-root-to-leaf-numbers/index.ts index 7a852819..372a0638 100644 --- a/sum-root-to-leaf-numbers/index.ts +++ b/sum-root-to-leaf-numbers/index.ts @@ -15,7 +15,7 @@ function pathSum(root: TreeNode | null): number[][] { function dfs( root: TreeNode, route: number[], - output: (route: number[]) => void + output: (route: number[]) => void, ) { if (!root.left && !root.right) { output([...route, root.val]); diff --git a/super-ugly-number/index.ts b/super-ugly-number/index.ts index c024ff83..f20599d4 100644 --- a/super-ugly-number/index.ts +++ b/super-ugly-number/index.ts @@ -1,6 +1,6 @@ export default function nthSuperUglyNumber( n: number, - primes: number[] + primes: number[], ): number { const dp: number[] = new Array(n + 1).fill(0); const m = primes.length; diff --git a/t9-lcci/index.ts b/t9-lcci/index.ts index 744ecdb6..f872ee07 100644 --- a/t9-lcci/index.ts +++ b/t9-lcci/index.ts @@ -1,16 +1,40 @@ export default function getValidT9Words( num: string, - words: string[] + words: string[], ): string[] { return words.filter((w) => Array.prototype.every.call( w, (c, i) => - num[i] === String(key[c.charCodeAt(0) - "a".charCodeAt(0)]) + num[i] === String(key[c.charCodeAt(0) - "a".charCodeAt(0)]), ) ); } const key = [ - 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 7, + 8, + 8, + 8, + 9, + 9, + 9, 9, ]; diff --git a/ternary-expression-parser/index.ts b/ternary-expression-parser/index.ts index 2998b11c..549fd345 100644 --- a/ternary-expression-parser/index.ts +++ b/ternary-expression-parser/index.ts @@ -16,7 +16,7 @@ function parseTernaryReverse(expression: string): string { return a === "T" ? b : c; } return s; - }) + }), ); } return expression; diff --git a/text-justification/index.ts b/text-justification/index.ts index 59177d23..f7e52b6e 100644 --- a/text-justification/index.ts +++ b/text-justification/index.ts @@ -1,6 +1,6 @@ export default function fullJustify( words: string[], - maxWidth: number + maxWidth: number, ): string[] { const L = words.length; const queue: string[] = []; @@ -39,13 +39,13 @@ export default function fullJustify( queue.push( tmp .map((t, i) => - i === T - ? t - : `${t}${" ".repeat( - space + (extra-- <= 0 ? 0 : 1) - )}` + i === T ? t : `${t}${ + " ".repeat( + space + (extra-- <= 0 ? 0 : 1), + ) + }` ) - .join("") + .join(""), ); } } diff --git a/time-needed-to-inform-all-employees/index.ts b/time-needed-to-inform-all-employees/index.ts index b175d86e..7e670213 100644 --- a/time-needed-to-inform-all-employees/index.ts +++ b/time-needed-to-inform-all-employees/index.ts @@ -2,7 +2,7 @@ function numOfMinutes( n: number, headID: number, manager: number[], - informTime: number[] + informTime: number[], ): number { const max: number[] = []; const pretime: number[] = new Array(n).fill(-1); @@ -12,8 +12,8 @@ function numOfMinutes( function dfs(currentNode: number): number { if (pretime[currentNode] >= 0) return pretime[currentNode]; - pretime[currentNode] = - informTime[manager[currentNode]] + dfs(manager[currentNode]); + pretime[currentNode] = informTime[manager[currentNode]] + + dfs(manager[currentNode]); return pretime[currentNode]; } diff --git a/total-cost-to-hire-k-workers/index.ts b/total-cost-to-hire-k-workers/index.ts index 263d0527..77021aa1 100644 --- a/total-cost-to-hire-k-workers/index.ts +++ b/total-cost-to-hire-k-workers/index.ts @@ -2,7 +2,7 @@ const compare = (a: number, b: number): number => a - b; export default function totalCost( costs: number[], k: number, - candidates: number + candidates: number, ): number { const n = costs.length; let ans = 0; diff --git a/transform-to-chessboard/index.ts b/transform-to-chessboard/index.ts index 9c57098e..81674bc8 100644 --- a/transform-to-chessboard/index.ts +++ b/transform-to-chessboard/index.ts @@ -23,21 +23,15 @@ export default function movesToChessboard(board: number[][]): number { const rowDiff = board.reduce((a, v, i) => a + Number(v[0] == i % 2), 0); const colDiff = board.reduce( (a, _v, i) => a + Number(board[0][i] == i % 2), - 0 + 0, ); - const rD = - n % 2 - ? rowDiff % 2 - ? n - rowDiff - : rowDiff - : Math.min(n - rowDiff, rowDiff); + const rD = n % 2 + ? rowDiff % 2 ? n - rowDiff : rowDiff + : Math.min(n - rowDiff, rowDiff); - const cD = - n % 2 - ? colDiff % 2 - ? n - colDiff - : colDiff - : Math.min(n - colDiff, colDiff); + const cD = n % 2 + ? colDiff % 2 ? n - colDiff : colDiff + : Math.min(n - colDiff, colDiff); return Math.floor((rD + cD) / 2); } diff --git a/trim-a-binary-search-tree/index.ts b/trim-a-binary-search-tree/index.ts index 902ad3a1..72238509 100644 --- a/trim-a-binary-search-tree/index.ts +++ b/trim-a-binary-search-tree/index.ts @@ -4,7 +4,7 @@ export default trimBST; function trimBST( root: TreeNode | null, low: number, - high: number + high: number, ): TreeNode | null { if (!root) return null; @@ -15,6 +15,6 @@ function trimBST( return new TreeNode( root.val, trimBST(root.left, low, high), - trimBST(root.right, low, high) + trimBST(root.right, low, high), ); } diff --git a/tweet-counts-per-frequency/index.ts b/tweet-counts-per-frequency/index.ts index ee7b3dfc..0d786967 100644 --- a/tweet-counts-per-frequency/index.ts +++ b/tweet-counts-per-frequency/index.ts @@ -6,13 +6,13 @@ export default class TweetCounts { #key_to_count = new Map(); recordTweet(tweetName: string, time: number): void { - const bst = - this.#name_to_bst.get(tweetName) ?? new BinarySearchTree(); + const bst = this.#name_to_bst.get(tweetName) ?? + new BinarySearchTree(); const node = bst.find(time); if (node) { this.#key_to_count.set( time, - (this.#key_to_count.get(time) ?? 0) + 1 + (this.#key_to_count.get(time) ?? 0) + 1, ); return; @@ -26,23 +26,22 @@ export default class TweetCounts { freq: string, tweetName: string, startTime: number, - endTime: number + endTime: number, ): number[] { const bst = this.#name_to_bst.get(tweetName); if (!bst) return []; - const length = - freq === "minute" - ? 60 - : freq === "hour" - ? 3600 - : freq === "day" - ? 86400 - : 0; + const length = freq === "minute" + ? 60 + : freq === "hour" + ? 3600 + : freq === "day" + ? 86400 + : 0; if (length === 0) { throw Error("invalid frequency"); } const result: number[] = Array( - Math.ceil((endTime - startTime + 1) / length) + Math.ceil((endTime - startTime + 1) / length), ).fill(0); traversal_bst_range(bst.root(), startTime, endTime, (num: number) => { const time = num; diff --git a/two-out-of-three/index.ts b/two-out-of-three/index.ts index 4c0bab09..f10724bc 100644 --- a/two-out-of-three/index.ts +++ b/two-out-of-three/index.ts @@ -1,7 +1,7 @@ function twoOutOfThree( nums1: number[], nums2: number[], - nums3: number[] + nums3: number[], ): number[] { const map = new Map>(); diff --git a/ugly-number-iii/index.ts b/ugly-number-iii/index.ts index 94caa139..0e352a24 100644 --- a/ugly-number-iii/index.ts +++ b/ugly-number-iii/index.ts @@ -2,7 +2,7 @@ export default function nthUglyNumber( n: number, a: number, b: number, - c: number + c: number, ): number { return Number(nthUglyBigInt(BigInt(n), BigInt(a), BigInt(b), BigInt(c))); } @@ -10,7 +10,7 @@ export function nthUglyBigInt( n: bigint, a: bigint, b: bigint, - c: bigint + c: bigint, ): bigint { // 先将数值转换为 BigInt 类型 (a = BigInt(a)), (b = BigInt(b)), (c = BigInt(c)), (n = BigInt(n)); @@ -33,8 +33,7 @@ export function nthUglyBigInt( // 二分查找丑数 while (l < r) { const mid = l + (r - l) / 2n; - const count = - mid / a + + const count = mid / a + mid / b + mid / c - mid / a_b - diff --git a/uncommon-words-from-two-sentences/index.ts b/uncommon-words-from-two-sentences/index.ts index ab674d04..98da5d18 100644 --- a/uncommon-words-from-two-sentences/index.ts +++ b/uncommon-words-from-two-sentences/index.ts @@ -1,6 +1,6 @@ export default function uncommonFromSentences( s1: string, - s2: string + s2: string, ): string[] { const a = s1.split(" "); diff --git a/unique-email-addresses/index.ts b/unique-email-addresses/index.ts index fc9c3478..4afa211f 100644 --- a/unique-email-addresses/index.ts +++ b/unique-email-addresses/index.ts @@ -5,6 +5,6 @@ export default function numUniqueEmails(emails: string[]): number { // deno-lint-ignore ban-ts-comment //@ts-ignore return first.split("+")[0].replaceAll(".", "") + "@" + second; - }) + }), ).size; } diff --git a/unique-morse-code-words/index.ts b/unique-morse-code-words/index.ts index 8afe38e6..c67eaca6 100644 --- a/unique-morse-code-words/index.ts +++ b/unique-morse-code-words/index.ts @@ -44,5 +44,5 @@ const MORSE = [ "--..", ]; const letterToMorse = new Map( - MORSE.map((v, i) => [String.fromCharCode(i + "a".charCodeAt(0)), v]) + MORSE.map((v, i) => [String.fromCharCode(i + "a".charCodeAt(0)), v]), ); diff --git a/ur2n8P/index.ts b/ur2n8P/index.ts index cfb8f40e..ba7c1f12 100644 --- a/ur2n8P/index.ts +++ b/ur2n8P/index.ts @@ -1,6 +1,6 @@ function sequenceReconstruction( nums: number[], - sequences: number[][] + sequences: number[][], ): boolean { const s = new Set(); for (const seq of sequences) { diff --git a/utf-8-validation/index.ts b/utf-8-validation/index.ts index c40236d7..841d19e1 100644 --- a/utf-8-validation/index.ts +++ b/utf-8-validation/index.ts @@ -25,7 +25,7 @@ function validUtf8(data: number[]): boolean { value >> 3 === 0b11110 && i + 3 < data.length && [data[i + 1], data[i + 2], data[i + 3]].every( - (v) => v >> 6 === 0b10 + (v) => v >> 6 === 0b10, ) ) { i += 3; diff --git a/valid-boomerang/index.ts b/valid-boomerang/index.ts index f7febdb2..ed67249b 100644 --- a/valid-boomerang/index.ts +++ b/valid-boomerang/index.ts @@ -19,6 +19,6 @@ export default function isBoomerang(points: number[][]): boolean { const innerProduct = dot(vector2, vector1); return !float64equals( Math.abs(innerProduct), - norm(vector2) * norm(vector1) + norm(vector2) * norm(vector1), ); } diff --git a/valid-square/index.ts b/valid-square/index.ts index 3852870a..b9225833 100644 --- a/valid-square/index.ts +++ b/valid-square/index.ts @@ -2,7 +2,7 @@ function validSquare( p1: number[], p2: number[], p3: number[], - p4: number[] + p4: number[], ): boolean { return ( isRightTriangle(p1, p2, p3) && @@ -12,12 +12,12 @@ function validSquare( ); } function isRightTriangle(p1: number[], p2: number[], p3: number[]) { - const d1 = - (p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]); - const d2 = - (p2[0] - p3[0]) * (p2[0] - p3[0]) + (p2[1] - p3[1]) * (p2[1] - p3[1]); - const d3 = - (p3[0] - p1[0]) * (p3[0] - p1[0]) + (p3[1] - p1[1]) * (p3[1] - p1[1]); + const d1 = (p1[0] - p2[0]) * (p1[0] - p2[0]) + + (p1[1] - p2[1]) * (p1[1] - p2[1]); + const d2 = (p2[0] - p3[0]) * (p2[0] - p3[0]) + + (p2[1] - p3[1]) * (p2[1] - p3[1]); + const d3 = (p3[0] - p1[0]) * (p3[0] - p1[0]) + + (p3[1] - p1[1]) * (p3[1] - p1[1]); if ( (d1 > d2 && d2 == d3 && d2 + d3 == d1) || (d2 > d1 && d1 == d3 && d1 + d3 == d2) || diff --git a/validate-binary-search-tree/index.ts b/validate-binary-search-tree/index.ts index 6ec50de6..0ba4f4a0 100644 --- a/validate-binary-search-tree/index.ts +++ b/validate-binary-search-tree/index.ts @@ -22,7 +22,7 @@ export default function isValidBST(root: TreeNode | null): boolean { } } }, - signal + signal, ); return result; } diff --git a/validate-binary-tree-nodes/index.ts b/validate-binary-tree-nodes/index.ts index 4323e5e0..f416b60c 100644 --- a/validate-binary-tree-nodes/index.ts +++ b/validate-binary-tree-nodes/index.ts @@ -1,7 +1,7 @@ export default function validateBinaryTreeNodes( n: number, leftChild: number[], - rightChild: number[] + rightChild: number[], ): boolean { const degree = Array(n).fill(0); for (const i of leftChild) { diff --git a/verifying-an-alien-dictionary/index.ts b/verifying-an-alien-dictionary/index.ts index f96cbb14..d1ed087f 100644 --- a/verifying-an-alien-dictionary/index.ts +++ b/verifying-an-alien-dictionary/index.ts @@ -6,8 +6,8 @@ export default function isAlienSorted(words: string[], order: string): boolean { const result = String.fromCharCode( ...Array.from(word).map( - (char) => "a".charCodeAt(0) + (char_to_index.get(char) ?? -1) - ) + (char) => "a".charCodeAt(0) + (char_to_index.get(char) ?? -1), + ), ); decode_cache.set(word, result); return result; @@ -20,7 +20,7 @@ export default function isAlienSorted(words: string[], order: string): boolean { } const char_to_index = new Map( - [...Array.from(order).entries()].map(([a, b]) => [b, a]) + [...Array.from(order).entries()].map(([a, b]) => [b, a]), ); return words.every((word, index, array) => { diff --git a/vertical-order-traversal-of-a-binary-tree/index.ts b/vertical-order-traversal-of-a-binary-tree/index.ts index dacd579e..25947b9a 100644 --- a/vertical-order-traversal-of-a-binary-tree/index.ts +++ b/vertical-order-traversal-of-a-binary-tree/index.ts @@ -19,13 +19,15 @@ export default function verticalTraversal(root: TreeNode | null): number[][] { current = next; } - for (const arr of Array.from(map) - .sort((a, b) => a[0] - b[0]) - .map((a) => a[1])) { + for ( + const arr of Array.from(map) + .sort((a, b) => a[0] - b[0]) + .map((a) => a[1]) + ) { res.push( arr .sort((a, b) => (a[0] === b[0] ? a[1] - b[1] : a[0] - b[0])) - .map((a) => a[1]) + .map((a) => a[1]), ); } return res; diff --git a/vvXgSW/index.ts b/vvXgSW/index.ts index b173d5e5..5d9273ac 100644 --- a/vvXgSW/index.ts +++ b/vvXgSW/index.ts @@ -2,7 +2,7 @@ import mergeTwoLists from "../merge-two-sorted-lists/index.ts"; import { ListNode } from "../reverse-linked-list/ListNode.ts"; export default function mergeKLists( - lists: Array + lists: Array, ): ListNode | null { const listsnotnull = lists.filter((a) => !!a) as Array; @@ -15,7 +15,7 @@ export default function mergeKLists( if (listsnotnull.length % 2) { return mergeTwoLists( listsnotnull[0], - mergeKLists(listsnotnull.slice(1)) + mergeKLists(listsnotnull.slice(1)), ); } else { const half = Math.floor(lists.length / 2) - 1; diff --git a/wMGN0t/index.ts b/wMGN0t/index.ts index e1631e44..49d0831a 100644 --- a/wMGN0t/index.ts +++ b/wMGN0t/index.ts @@ -1,7 +1,7 @@ function storedEnergy( storeLimit: number, power: number[], - supply: number[][] + supply: number[][], ): number { const { min, max } = Math; let sum = 0; diff --git a/wildcard-matching/index.ts b/wildcard-matching/index.ts index 9ba63a11..6c060677 100644 --- a/wildcard-matching/index.ts +++ b/wildcard-matching/index.ts @@ -42,7 +42,7 @@ function check_fixs(s: string, words: string[]): boolean { if (suffix) { const matched = str.match( //@ts-ignore - new RegExp(`^(.*?)${suffix.replaceAll("?", ".")}$`) + new RegExp(`^(.*?)${suffix.replaceAll("?", ".")}$`), ); if (!matched) return false; str = matched[1]; @@ -50,7 +50,7 @@ function check_fixs(s: string, words: string[]): boolean { if (prefix) { const matched = str.match( //@ts-ignore - new RegExp(`^${prefix.replaceAll("?", ".")}(.*?)$`) + new RegExp(`^${prefix.replaceAll("?", ".")}(.*?)$`), ); if (!matched) return false; str = matched[1]; @@ -65,7 +65,7 @@ function check_regular(s: string, p: string): boolean { return new RegExp( //@ts-ignore "^" + p.replaceAll("?", ".").replaceAll(/\*+/g, ".*") + "$", - "g" + "g", ).test(s); } function check_words(s: string, words: string[]): boolean { @@ -73,13 +73,13 @@ function check_words(s: string, words: string[]): boolean { if (words.length === 0) return true; const mid_index = words.reduce( (a, v, i) => (v.length > words[a].length ? i : a), - Math.floor(words.length / 2) + Math.floor(words.length / 2), ); // const mid_index = Math.floor(words.length / 2); const middle = words[mid_index]; const matched_array = Array.from( //@ts-ignore - s.matchAll(new RegExp(`${middle.replaceAll("?", ".")}`, "g")) + s.matchAll(new RegExp(`${middle.replaceAll("?", ".")}`, "g")), ); // console.log(matched_array); diff --git a/word-break-ii/index.ts b/word-break-ii/index.ts index 5af24653..4ff2ad82 100644 --- a/word-break-ii/index.ts +++ b/word-break-ii/index.ts @@ -5,7 +5,7 @@ export default function wordBreak(s: string, wordDict: string[]): string[] { return []; } const lens = Array.from(new Set(wordDict.map((a) => a.length))).sort( - (a, b) => a - b + (a, b) => a - b, ); const n: number = s.length; const set: Set = new Set(wordDict); diff --git a/word-break/index.ts b/word-break/index.ts index dc58b277..d25069b2 100644 --- a/word-break/index.ts +++ b/word-break/index.ts @@ -8,7 +8,7 @@ function wordBreak(s: string, wordDict: string[]): boolean { const set = new Set(wordDict); const lens = Array.from(new Set(wordDict.map((a) => a.length))).sort( - (a, b) => a - b + (a, b) => a - b, ); const cached = new Map(); diff --git a/word-ladder-ii/index.ts b/word-ladder-ii/index.ts index eff149fb..7debc930 100644 --- a/word-ladder-ii/index.ts +++ b/word-ladder-ii/index.ts @@ -5,7 +5,7 @@ function dfs( length: number, path: string[], endWord: string, - wordlevel: Map + wordlevel: Map, ) { if (path.length > length) return; if (current === endWord && path.length === length) { @@ -24,7 +24,7 @@ function dfs( function findLadders( beginWord: string, endWord: string, - wordList: string[] + wordList: string[], ): string[][] { const res: string[][] = []; @@ -53,7 +53,7 @@ function ladderLength( endWord: string, wordList: string[], edge: Map>, - wordlevel: Map + wordlevel: Map, ): number { const words = new Set(wordList); if (!words.has(endWord)) return 0; diff --git a/word-ladder/index.ts b/word-ladder/index.ts index 6e6dc03e..80fc986a 100644 --- a/word-ladder/index.ts +++ b/word-ladder/index.ts @@ -1,7 +1,7 @@ export default function ladderLength( beginWord: string, endWord: string, - wordList: string[] + wordList: string[], ): number { const words = new Set(wordList); if (!words.has(endWord)) return 0; diff --git a/word-search-ii/index.ts b/word-search-ii/index.ts index 06772d53..c341429d 100644 --- a/word-search-ii/index.ts +++ b/word-search-ii/index.ts @@ -6,7 +6,7 @@ function findWords(board: string[][], words: string[]): string[] { if (board.length === 1 && board[0].length === 1) { return words.filter( - (word) => word.length === 1 && word === board[0][0] + (word) => word.length === 1 && word === board[0][0], ); } if (words.length === 0) return []; @@ -68,7 +68,7 @@ function dfs( col: number, prefix: string, now: PrefixTree, - result: Set + result: Set, ) { const node = now.children.get(board[i][j]); if (!node) return; diff --git a/zL2zJU/index.ts b/zL2zJU/index.ts index ae73c457..51f31ef1 100644 --- a/zL2zJU/index.ts +++ b/zL2zJU/index.ts @@ -1,6 +1,6 @@ export default function observingPeriodicity( record: number[], - robot: number[] + robot: number[], ): number[] { const n = robot.length; const res: number[] = Array(n).fill(0); @@ -12,7 +12,7 @@ function backtrack( robotIndex: number, record: number[], robot: number[], - res: number[] + res: number[], ): boolean { const n = robot.length; const m = record.length; @@ -22,7 +22,8 @@ function backtrack( const maxPeriod = m - robot[robotIndex]; - loop: for (let i = 1; i <= maxPeriod; i++) { + loop: + for (let i = 1; i <= maxPeriod; i++) { for (let j = robot[robotIndex]; j < m; j += i) { if (record[j] === 0) continue loop; }