classSolution:defisAnagram(self, s:str, t:str)->bool:from collections import defaultdict
iflen(s)!=len(t):returnFalse
hashset = defaultdict(int)for i inrange(len(s)):
hashset[s[i]]+=1
hashset[t[i]]-=1for k, v in hashset.items():if v <0:returnFalsereturnTrue
349. 两个数组的交集
代码思路
classSolution:defintersection(self, nums1: List[int], nums2: List[int])-> List[int]:from collections import defaultdict
hashset1 = defaultdict(int)
hashset2 = defaultdict(int)iflen(nums1)<len(nums2):long= nums2
short = nums1
else:long= nums1
short = nums2
for i inrange(len(long)):
hashset1[long[i]]+=1if i <len(short):
hashset2[short[i]]+=1
result =[]for k, v in hashset1.items():if hashset2[k]>0:
result.append(k)return result
pre.next= cur.next