deno.land / x / masx200_leetcode_test@10.6.5 / find-positive-integer-solution-for-a-given-equation / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { CustomFunction } from "./CustomFunction.ts";
function findSolution(customfunction: CustomFunction, z: number): number[][] { const min = customfunction.f(1, 1); const max = customfunction.f(1000, 1000); if (z < min || z > max) return [];
const res: number[][] = []; for (let i = 1, j = 1000; i <= 1000 && j >= 1;) { const diff = customfunction.f(i, j) - z; if (diff === 0) { res.push([i, j]); i++; j--; } else if (diff < 0) { i++; } else { j--; } } return res;}export default findSolution;
masx200_leetcode_test

Version Info

Tagged at
a year ago