class Solution:
def isAnagram(self, s: str, t: str) -> bool:
hashtable = {}
for c in s:
hashtable[c] = hashtable.get(c,0) + 1
for c in t:
if c in hashtable:
hashtable[c] -= 1
else:
return False
for count in hashtable.values():
if count != 0:
return False
return True
class Solution:
def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]:
hashset_1 = set()
hashset_2 = set()
for i in nums1:
hashset_1.add(i)
for j in nums2:
if j in hashset_1:
hashset_2.add(j)
return list(hashset_2)
class Solution:
def isHappy(self, n: int) -> bool:
slow = n
fast = n
while self.get_sum(fast) != 1 and self.get_sum(self.get_sum(fast)):
slow = self.get_sum(slow)
fast = self.get_sum(self.get_sum(fast))
if slow == fast:
return False
return True
def get_sum(self,n: int) -> int:
new_num = 0
while n:
n, r = divmod(n, 10)
new_num += r ** 2
return new_num
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
result = []
for i in range(0, len(nums)):
for j in range(i + 1, len(nums)):
if nums[i] + nums[j] == target:
result.append(i)
result.append(j)
return result
return result