Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 142890a

Browse files
add one brute force solution for 1237
1 parent ef2b317 commit 142890a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.fishercoder.solutions;
22

3+
import java.util.ArrayList;
4+
import java.util.Arrays;
35
import java.util.List;
46

57
/**
@@ -41,16 +43,26 @@ public class _1237 {
4143

4244
// This is the custom function interface.
4345
// You should not implement it, or speculate about its implementation
44-
interface CustomFunction {
46+
abstract class CustomFunction {
4547
// Returns f(x, y) for any given positive integers x and y.
4648
// Note that f(x, y) is increasing with respect to both x and y.
4749
// i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)
48-
public int f(int x, int y);
50+
public abstract int f(int x, int y);
4951
}
5052

5153
public static class Solution1 {
54+
/**Time: O(1) since it's bound by 1 <= x, y <= 1000
55+
* Space: O(1)*/
5256
public List<List<Integer>> findSolution(CustomFunction customfunction, int z) {
53-
return null;
57+
List<List<Integer>> result = new ArrayList<>();
58+
for (int x = 1; x <= 1000; x++) {
59+
for (int y = 1; y <= 1000; y++) {
60+
if (customfunction.f(x, y) == z) {
61+
result.add(Arrays.asList(x, y));
62+
}
63+
}
64+
}
65+
return result;
5466
}
5567
}
5668

0 commit comments

Comments
 (0)