File tree Expand file tree Collapse file tree 3 files changed +91
-0
lines changed
solution/1200-1299/1237.Find Positive Integer Solution for a Given Equation Expand file tree Collapse file tree 3 files changed +91
-0
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,38 @@ class Solution {
148
148
}
149
149
```
150
150
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
+
151
183
### ** C++**
152
184
153
185
``` cpp
Original file line number Diff line number Diff line change @@ -140,6 +140,38 @@ class Solution {
140
140
}
141
141
```
142
142
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
+
143
175
### ** C++**
144
176
145
177
``` cpp
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments