CSDN周赛第37期题解（Python版）

18 篇文章 1 订阅
3 篇文章 0 订阅

1、题目名称：幼稚班作业

def solution(self, arr):
result = None
arr = sorted(arr)
if arr[0] + arr[1] > arr[2] and arr[2] - arr[0] < arr[1]:
result = 1
elif arr[1] + arr[2] > arr[3] and arr[3] - arr[1] < arr[2]:
result = 1
elif arr[0] + arr[1] == arr[2] or arr[1] + arr[2] == arr[3]:
result = 0
else:result = -1
return result


2、题目名称：异或和

def solution(self, N):
if N% 4 == 0:return N
elif N%4==1:return 1
elif N%4==2:return N+1
else:
return 0


3、题目名称：大整数替换数位

def solution(self, M, N):
rem = sum(int(n) for n in N) % 9
count = 0
for i in range(M):
for j in range(10):
if str(j) != N[i]:
new_N = (rem+j-int(N[i])) %9
if new_N==1:
count+=1
return count


4、题目名称：莫名其妙的键盘

from functools import lru_cache
@lru_cache()
def funXX(): #调用的方法
pass

from functools import lru_cache
@lru_cache()
def solution(self, s):
letter = ('a','e','i','o','u')
result = None
if len(s) == 1:return 1
result = 0
if s[0] in letter:
result += self.solution(s[1:][::-1])
if s[-1] not in letter:
result += self.solution(s[:-1])
return result

• 1
点赞
• 1
收藏
觉得还不错? 一键收藏
• 打赏
• 0
评论
03-16 930
03-30 386
03-20 170
03-16 533
02-24 5037
05-05 315
06-11
08-06 396
08-08 200
03-31

Pandas_007

¥1 ¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。