classSolution:defisAnagram(self, s:str, t:str)->bool:
record =[0]*26for i in s:#并不需要记住字符a的ASCII,只要求出一个相对数值就可以了
record[ord(i)-ord("a")]+=1for i in t:
record[ord(i)-ord("a")]-=1for i inrange(26):if record[i]!=0:#record数组如果有的元素不为零0,说明字符串s和t 一定是谁多了字符或者谁少了字符。returnFalsereturnTrue
classSolution:defintersection(self, nums1: List[int], nums2: List[int])-> List[int]:
pool =set()
res =set()for num in nums1:
pool.add(num)for num in nums2:if num in pool:
res.add(num)returnlist(res)
classSolution:defisHappy(self, n:int)->bool:
pool =set()while n !=1:
res =0for i instr(n):
res +=int(i)**2if res in pool:returnFalseelse:
pool.add(res)
n = res
returnTrue
classSolution:deftwoSum(self, nums: List[int], target:int)-> List[int]:
_map ={}for i, v inenumerate(nums):if v in _map:return[i, _map[v]]else:
_map[target - v]= i