classSolution:defisAnagram(self, s:str, t:str)->bool:
hash_table =[0]*26for i inrange(len(s)):
hash_table[ord(s[i])-ord("a")]+=1for i inrange(len(t)):
hash_table[ord(t[i])-ord("a")]-=1print(hash_table)for i inrange(len(hash_table)):if hash_table[i]!=0:returnFalsereturnTrue
classSolution:defgetIntersectionNode(self, headA: ListNode, headB: ListNode)-> ListNode:
a,b = headA, headB
while a!=b:
a = a.nextif a else headB
b = b.nextif b else headA
return b
Happy Number
classSolution:defisHappy(self, n:int)->bool:defcalculate(number):
summation =0while number:
summation +=(number %10)**2
number = number //10return summation
record =set()whileTrue:
n = calculate(n)if n ==1:returnTrueif n in record:returnFalseelse:
record.add(n)
Two Sum
classSolution:deftwoSum(self, nums: List[int], target:int)-> List[int]:
hash_table =dict()for i, v inenumerate(nums):if(target - v)in hash_table:return[hash_table[target - v], i]else:
hash_table[v]= i
return[]