题目描述:
class Solution: def findSolution(self, customfunction: ‘CustomFunction‘, z: int) -> List[List[int]]: res = [] for i in range(1,1001): for j in range(1,1001): if customfunction.f(i,j) == z: res.append([i,j]) if customfunction.f(i,j) > z: break return res
另:O(N)
class Solution(object): def findSolution(self, customfunction, z): x = 1000 y = 1 ans = [] while 1 <= x <= 1000 and 1 <= y <= 1000: z0 = customfunction.f(x, y) if z0 == z: ans.append([x, y]) x -= 1 y += 1 elif z0 > z: x -= 1 elif z0 < z: y += 1 return ans
原文地址:https://www.cnblogs.com/oldby/p/11750630.html
时间: 2024-10-10 20:53:24