第一题
照题目叙述写
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
不过有点想睡 放弃
大家加油