Find Positive Integer Solution for a Given Equation LeetCode solution in JavaScript

1
/**
2
* // This is the CustomFunction's API interface.
3
* // You should not implement it, or speculate about its implementation
4
* function CustomFunction() {
5
* @param {integer, integer} x, y
6
* @return {integer}
7
* this.f = function(x, y) {
8
* ...
9
* };
10
* };
11
*/
12

13
/**
14
* @param {CustomFunction} customfunction
15
* @param {integer} z
16
* @return {integer[][]}
17
*/
18
var findSolution = function (customfunction, z) {
19
var ans = [];
20
var x = 1,
21
y = 1000;
22
while (x <= 1000 && y > 0) {
23
if (customfunction.f(x, y) > z) {
24
y--;
25
} else if (customfunction.f(x, y) < z) {
26
x++;
27
} else {
28
ans.push([x, y]);
29
x++;
30
y--;
31
}
32
}
33
return ans;
34
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0