Skip to content

Commit 90c4571

Browse files
committed
feat: add typescript solution to lc problem: No.1237.Find Positive Integer Solution for a Given Equation
1 parent 961f502 commit 90c4571

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

solution/1200-1299/1237.Find Positive Integer Solution for a Given Equation/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,38 @@ class Solution {
148148
}
149149
```
150150

151+
### **TypeScript**
152+
153+
```ts
154+
/**
155+
* // This is the CustomFunction's API interface.
156+
* // You should not implement it, or speculate about its implementation
157+
* class CustomFunction {
158+
* f(x: number, y: number): number {}
159+
* }
160+
*/
161+
162+
function findSolution(customfunction: CustomFunction, z: number): number[][] {
163+
// 二分
164+
let ans = [];
165+
for (let i = 1; i <= 1000; i++) {
166+
let left = 1, right = 1000;
167+
while (left < right) {
168+
let mid = (left + right) >> 1;
169+
if (customfunction.f(i, mid) >= z) {
170+
right = mid;
171+
} else {
172+
left = mid + 1;
173+
}
174+
}
175+
if (customfunction.f(i, left) == z) {
176+
ans.push([i, left]);
177+
}
178+
}
179+
return ans;
180+
};
181+
```
182+
151183
### **C++**
152184

153185
```cpp

solution/1200-1299/1237.Find Positive Integer Solution for a Given Equation/README_EN.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,38 @@ class Solution {
140140
}
141141
```
142142

143+
### **TypeScript**
144+
145+
```ts
146+
/**
147+
* // This is the CustomFunction's API interface.
148+
* // You should not implement it, or speculate about its implementation
149+
* class CustomFunction {
150+
* f(x: number, y: number): number {}
151+
* }
152+
*/
153+
154+
function findSolution(customfunction: CustomFunction, z: number): number[][] {
155+
// 二分
156+
let ans = [];
157+
for (let i = 1; i <= 1000; i++) {
158+
let left = 1, right = 1000;
159+
while (left < right) {
160+
let mid = (left + right) >> 1;
161+
if (customfunction.f(i, mid) >= z) {
162+
right = mid;
163+
} else {
164+
left = mid + 1;
165+
}
166+
}
167+
if (customfunction.f(i, left) == z) {
168+
ans.push([i, left]);
169+
}
170+
}
171+
return ans;
172+
};
173+
```
174+
143175
### **C++**
144176

145177
```cpp
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* // This is the CustomFunction's API interface.
3+
* // You should not implement it, or speculate about its implementation
4+
* class CustomFunction {
5+
* f(x: number, y: number): number {}
6+
* }
7+
*/
8+
9+
function findSolution(customfunction: CustomFunction, z: number): number[][] {
10+
// 二分
11+
let ans = [];
12+
for (let i = 1; i <= 1000; i++) {
13+
let left = 1, right = 1000;
14+
while (left < right) {
15+
let mid = (left + right) >> 1;
16+
if (customfunction.f(i, mid) >= z) {
17+
right = mid;
18+
} else {
19+
left = mid + 1;
20+
}
21+
}
22+
if (customfunction.f(i, left) == z) {
23+
ans.push([i, left]);
24+
}
25+
}
26+
return ans;
27+
};

0 commit comments

Comments
 (0)