Find Positive Integer Solution for a Given Equation LeetCode solution in Java
1class Solution {2private int binarySearch(int ans, int x, CustomFunction func) {3int left = 1, right = 1000;4while (left <= right) {5int mid = left + (right - left) / 2;67int res = func.f(x, mid);89if (res == ans) {10return mid;11}12if (res < ans) {13left = mid + 1;14} else {15right = mid - 1;16}17}18return -1;19}2021public List<List<Integer>> findSolution(CustomFunction customfunction, int z) {22List<List<Integer>> res = new ArrayList<>();2324for (int i = 1; i <= 1000; i++) {25int ans = binarySearch(z, i, customfunction);26if (ans != -1) {27List<Integer> temp = new ArrayList<>();28temp.add(i);29temp.add(ans);30res.add(temp);31}32if (customfunction.f(i, 1) > z) {33break;34}35}36return res;37}38}