Re: [闲聊] 每日leetcode

楼主: argorok (s.green)   2024-06-17 14:25:41
※ 引述《yam276 (虚构史学家)》之铭言:
: ※ 引述《sustainer123 (caster )》之铭言:
: : https://leetcode.com/problems/sum-of-square-numbers
: : 633. Sum of Square Numbers
: : 给定一非负整数C 请回传是否存在a,b两数使得a**2 + b**2 == c
: : 思路:
: : two pointer
你板剩我只会暴力法了:(
再想办法用hash table优化一下时间
class Solution:
def judgeSquareSum(self, c: int) -> bool:
n = int(math.sqrt(c)) + 1
self.square = {}
for i in range(n):
self.square[i*i] = i*i
for i in range(n):
if c - self.square[i*i] in self.square:
return True
return False
作者: Rushia (みけねこ的鼻屎)   2024-06-17 14:27:00
我也用HASHTABLE= =像TWO SUM那样
作者: smart0eddie (smart0eddie)   2024-06-17 14:31:00
泥板剩我只会抄作业了你index都算完i*i了还要取值吗
楼主: argorok (s.green)   2024-06-17 14:32:00
其实是不用 随便乱写有过就算了==

Links booklink

Contact Us: admin [ a t ] ucptt.com