标签:break etc app obj col end tco while function
题目描述:
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
leetcode-160场周赛-5238-找出给定方程的正整数解
标签:break etc app obj col end tco while function
原文地址:https://www.cnblogs.com/oldby/p/11750630.html