leetcode Weekly Contest 408

作者: sustainer123 (caster)   2024-07-28 11:22:05
第一題
照題目敘述寫
Python Code:
class Solution:
def canAliceWin(self, nums: List[int]) -> bool:
count = 0
for n in nums:
if n < 10:
count += n
k = sum(nums)
if (k-count) > count or count > (k-count):
return True
else:
return False
第二題
其實就找質數的平方數
只是不能直接整個查找
不然會TLE
Python Code:
class Solution:
def nonSpecialCount(self, l: int, r: int) -> int:
def is_prime(num):
if num <= 1:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
special_count = 0
p = int(l ** 0.5)
while p ** 2 <= r:
if is_prime(p):
square = p ** 2
if l <= square <= r:
special_count += 1
p += 1
total_numbers = r - l + 1
return total_numbers - special_count
第三題
應該是sliding window
不過有點想睡 放棄
大家加油
作者: Smallsh (Smallsh)   2023-07-28 11:22:00
大師
作者: DJYOMIYAHINA (通通打死)   2024-07-28 11:46:00
大濕 我今天0題
作者: sustainer123 (caster)   2024-07-28 11:49:00
要是我有工作 我也0題 唉
作者: dont   2024-07-28 11:58:00
第4題 對可連接的circle做union find再看圓碰到幾個邊或(X,Y),(0,0)
作者: sustainer123 (caster)   2024-07-28 12:02:00
我只感覺是graph 但完全沒想法

Links booklink

Contact Us: admin [ a t ] ucptt.com