class Solution:
def fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int:
res = 0
hashtable = dict()
for i in nums1:
for j in nums2:
tot = i+j
hashtable[tot] = hashtable.get(tot,0)+1
for i in nums3:
for j in nums4:
res += hashtable.get(-i-j,0)
return res
class Solution:
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
hashtable = dict()
for i in magazine:
if i in hashtable:
hashtable[i]+=1
else:
hashtable[i] = 1
for i in ransomNote:
if i in hashtable:
hashtable[i]-=1
if hashtable[i]<0:
return False
else:
return False
return True
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
ans = []
nums.sort()
print(nums)
for i in range(len(nums)):
if nums[i] > 0:
return ans
if i > 0 and nums[i] == nums[i-1]:
continue
left = i+1
right = len(nums)-1
while left < right:
total = nums[i]+ nums[left]+ nums[right]
if total > 0:
right-=1
elif total < 0:
left +=1
else:
ans.append([nums[i],nums[left],nums[right]])
print("l",i,left,right)
while right > left and nums[right] == nums[right-1]:
right-=1
while right > left and nums[left] == nums[left+1]:
left+=1
right-=1
left+=1
# print(left,right)
return ans