|
1 | 1 | package com.fishercoder.solutions;
|
2 | 2 |
|
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.Arrays; |
3 | 5 | import java.util.List;
|
4 | 6 |
|
5 | 7 | /**
|
@@ -41,16 +43,26 @@ public class _1237 {
|
41 | 43 |
|
42 | 44 | // This is the custom function interface.
|
43 | 45 | // You should not implement it, or speculate about its implementation
|
44 |
| - interface CustomFunction { |
| 46 | + abstract class CustomFunction { |
45 | 47 | // Returns f(x, y) for any given positive integers x and y.
|
46 | 48 | // Note that f(x, y) is increasing with respect to both x and y.
|
47 | 49 | // 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); |
49 | 51 | }
|
50 | 52 |
|
51 | 53 | public static class Solution1 {
|
| 54 | + /**Time: O(1) since it's bound by 1 <= x, y <= 1000 |
| 55 | + * Space: O(1)*/ |
52 | 56 | 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; |
54 | 66 | }
|
55 | 67 | }
|
56 | 68 |
|
|
0 commit comments