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