今天做了1到算法,2道模拟题:
递归:
class Solution:
def mySqrt(self, x: int) -> int:
if x <= 1:
return x
r = x
while r > x / r:
r = (r + x / r) // 2
return int(r)
字符串操作
S = input()
alpha_switch = int(input())
n = int(input())
for _ in range(n):
s_ = input()
if alpha_switch == 1:
if S in s_:
print(s_)
else:
if S.upper() in s_.upper():
print(s_)
数列求值(斐波那契)
arr = [0 for _ in range(20190325)]
arr[0] = arr[1] = arr[2] = 1
for i in range(3, 20190324):
arr[i] = (arr[i - 1] + arr[i - 2] + arr[i - 3]) % 10000
print(arr[20190323])