avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

1237. Find out the positive combination of the given square One question daily

  2024-01-01        
字数统计: 168字   |   阅读时长: 1min

topic:

2023-02-18 (1).png
1237. Find out the positive combination of the given square.md

Thought:

Want to be complicated,It turned out to be intended to recover,Then constantly find out the solution。Then Ling Shen tells us:In fact, this question is a double pointer,One on the far left is on the right。
Monoly increase function,XCan only increase,YCan only reduce,So iff(x,y)<z,ExplainXIt’s time to increase,vice versa。

Because you need to continue to find after equal,So continue f(x,y)<zTalent operation,After modificationf(x+1,y)>f(x,y)=z,Depending on the circumstances 2,Can y minus one。

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution:
def findSolution(self, customfunction: 'CustomFunction', z: int) -> List[List[int]]:
ans = []
x, y = 1, 1000
while x <= 1000 and y:
res = customfunction.f(x, y)
if res < z:
x += 1
elif res > z:
y -= 1
else:
ans.append([x, y])
x += 1
y -= 1
return ans
IF
1

  • Python
  • answer

扫一扫,分享到微信

微信分享二维码
1250. examine「Good array」 One question daily
142.Ring linkedII
目录
  1. 1. topic:
  2. 2. Thought:
  3. 3. Code:

150 篇 | 131.7k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号