Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitadac78a

Browse files
refactor 1237
1 parentaf70a98 commitadac78a

File tree

1 file changed

+7
-40
lines changed

1 file changed

+7
-40
lines changed

‎src/main/java/com/fishercoder/solutions/_1237.java

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,6 @@
44
importjava.util.Arrays;
55
importjava.util.List;
66

7-
/**
8-
* 1237. Find Positive Integer Solution for a Given Equation
9-
*
10-
* Given a function f(x, y) and a value z, return all positive integer pairs x and y where f(x,y) == z.
11-
* The function is constantly increasing, i.e.:
12-
*
13-
* f(x, y) < f(x + 1, y)
14-
* f(x, y) < f(x, y + 1)
15-
* The function interface is defined like this:
16-
*
17-
* interface CustomFunction {
18-
* public:
19-
* // Returns positive integer f(x, y) for any given positive integer x and y.
20-
* int f(int x, int y);
21-
* };
22-
* For custom testing purposes you're given an integer function_id and a target z as input,
23-
* where function_id represent one function from an secret internal list, on the examples you'll know only two functions from the list.
24-
* You may return the solutions in any order.
25-
*
26-
* Example 1:
27-
* Input: function_id = 1, z = 5
28-
* Output: [[1,4],[2,3],[3,2],[4,1]]
29-
* Explanation: function_id = 1 means that f(x, y) = x + y
30-
*
31-
* Example 2:
32-
* Input: function_id = 2, z = 5
33-
* Output: [[1,5],[5,1]]
34-
* Explanation: function_id = 2 means that f(x, y) = x * y
35-
*
36-
* Constraints:
37-
* 1 <= function_id <= 9
38-
* 1 <= z <= 100
39-
* It's guaranteed that the solutions of f(x, y) == z will be on the range 1 <= x, y <= 1000
40-
* It's also guaranteed that f(x, y) will fit in 32 bit signed integer if 1 <= x, y <= 1000
41-
*/
427
publicclass_1237 {
438

449
// This is the custom function interface.
@@ -51,8 +16,10 @@ abstract class CustomFunction {
5116
}
5217

5318
publicstaticclassSolution1 {
54-
/**Time: O(x*y)
55-
* Space: O(1)*/
19+
/**
20+
* Time: O(x*y)
21+
* Space: O(1)
22+
*/
5623
publicList<List<Integer>>findSolution(CustomFunctioncustomfunction,intz) {
5724
List<List<Integer>>result =newArrayList<>();
5825
for (intx =1;x <=1000;x++) {
@@ -69,7 +36,7 @@ public List<List<Integer>> findSolution(CustomFunction customfunction, int z) {
6936
publicstaticclassSolution2 {
7037
/**
7138
* linear search
72-
*
39+
*<p>
7340
* Time: O(x + y)
7441
* Space: O(1)
7542
*/
@@ -94,10 +61,10 @@ public List<List<Integer>> findSolution(CustomFunction customfunction, int z) {
9461
publicstaticclassSolution3 {
9562
/**
9663
* binary search
97-
*
64+
* <p>
9865
* Time: O(xlogy)
9966
* Space: O(1)
100-
* */
67+
*/
10168
publicList<List<Integer>>findSolution(CustomFunctioncustomfunction,intz) {
10269
List<List<Integer>>result =newArrayList<>();
10370
for (intx =1;x <=1000;x++) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp