-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindPositiveIntegerSolutionforaGivenEquation.py
More file actions
36 lines (31 loc) · 1.1 KB
/
findPositiveIntegerSolutionforaGivenEquation.py
File metadata and controls
36 lines (31 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# Source: https://leetcode.com/problems/find-positive-integer-solution-for-a-given-equation/
# Author: Miao Zhang
# Date: 2021-04-19
"""
This is the custom function interface.
You should not implement it, or speculate about its implementation
class CustomFunction:
# Returns f(x, y) for any given positive integers x and y.
# Note that f(x, y) is increasing with respect to both x and y.
# i.e. f(x, y) < f(x + 1, y), f(x, y) < f(x, y + 1)
def f(self, x, y):
"""
class Solution:
def findSolution(self, customfunction: 'CustomFunction', z: int) -> List[List[int]]:
res = []
for x in range(1, 1001):
if customfunction.f(x, 1) > z: break
l, r = 1, 1001
while l < r:
m = l + (r - l) // 2
t = customfunction.f(x, m)
if t > z:
r = m
elif t < z:
l = m + 1
else:
res.append([x, m])
break
return res