Skip to content

Commit 708cdb8

Browse files
authored
Create find-positive-integer-solution-for-a-given-equation.py
1 parent e5a2abb commit 708cdb8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
"""
5+
This is the custom function interface.
6+
You should not implement it, or speculate about its implementation
7+
class CustomFunction:
8+
# Returns f(x, y) for any given positive integers x and y.
9+
# Note that f(x, y) is increasing with respect to both x and y.
10+
# i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)
11+
def f(self, x, y):
12+
13+
"""
14+
class Solution(object):
15+
def findSolution(self, customfunction, z):
16+
"""
17+
:type num: int
18+
:type z: int
19+
:rtype: List[List[int]]
20+
"""
21+
result = []
22+
x, y = 1, 1
23+
while customfunction.f(x, y) < z:
24+
y += 1
25+
while y > 0:
26+
while y > 0 and customfunction.f(x, y) > z:
27+
y -= 1
28+
if y > 0 and customfunction.f(x, y) == z:
29+
result.append([x, y])
30+
x += 1
31+
return result

0 commit comments

Comments
 (0)