第一題
照題目敘述寫
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
不過有點想睡 放棄
大家加油