diff --git a/problems/0018.四数之和.md b/problems/0018.四数之和.md index bad258c1..348f2f73 100644 --- a/problems/0018.四数之和.md +++ b/problems/0018.四数之和.md @@ -212,6 +212,7 @@ class Solution(object): # good thing about using python is you can use set to drop duplicates. ans = set() + # ans = [] # save results by list() for i in range(len(nums)): for j in range(i + 1, len(nums)): for k in range(j + 1, len(nums)): @@ -220,10 +221,16 @@ class Solution(object): # make sure no duplicates. count = (nums[i] == val) + (nums[j] == val) + (nums[k] == val) if hashmap[val] > count: - ans.add(tuple(sorted([nums[i], nums[j], nums[k], val]))) - else: - continue - return ans + ans_tmp = tuple(sorted([nums[i], nums[j], nums[k], val])) + ans.add(ans_tmp) + # Avoiding duplication in list manner but it cause time complexity increases + # if ans_tmp not in ans: + # ans.append(ans_tmp) + else: + continue + return list(ans) + # if used list() to save results, just + # return ans ```