#####无重复字符的最长子串
def lengthOfLongestSubstring(s):
last = {}
ent = {}
for i in s:
if i in last:
ent[''.join(last.keys())] = sum(last.values())
last = {}
last[i] = 1
else:
last[i] = 1
ent[''.join(last.keys())] = sum(last.values())
print(ent)
aww = lengthOfLongestSubstring('abcabcbb')
print(aww)
######3
# 🐸台阶跳
def climbStairs(n):
if n ==1:
return 1
elif n==2:
return 2
else:
return climbStairs(n-1) + climbStairs(n-2)
wqq = climbStairs(10)
print(wqq)
# 数组中出现次数超过一半的数字
def MoreThanHalfNum_Solution(numbers):
if not numbers: return 0
dict1 ={}
for i in numbers:
if dict1.get(i):
dict1[i] += 1
else:
dict1[i] = 1
a = sorted(dict1.items(),key=lambda x: x[1],reverse=True)
res = a[0][0]
return res if numbers.count(res) > len(numbers) / 2 else 0
a = MoreThanHalfNum_Solution([1,2,3,2,2,2,5,4,2])
print(a)
# 求质数
num=[]
for i in range(2,10):
for j in range(2,i):
if(i%j==0):
break
else:
num.append(i)
print(num)
# 斐波那契数列
number=10
def Fibonacci(number):
n, a, b = 0, 0, 1
while n < number:
yield b
a, b = b, a + b
n = n + 1
s = Fibonacci(number)
print(list(s))