Skip to content

Added README and 3Sum files #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions 0015/3Sum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
nums.sort()
ans = set()
for i in range(len(nums) - 2):
j = i + 1
k = len(nums) - 1
while k > j:
s = nums[i] + nums[j] + nums[k]
if s == 0:
ans.add((nums[i], nums[j], nums[k]))
j += 1
elif s < 0:
j += 1
else:
k -= 1
return list(ans)
30 changes: 30 additions & 0 deletions 0015/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 3Sum
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Notice that the solution set must not contain duplicate triplets.



## Example 1:

Input: nums = [-1,0,1,2,-1,-4]

Output: [[-1,-1,2],[-1,0,1]]

## Example 2:

Input: nums = []

Output: []

## Example 3:

Input: nums = [0]

Output: []


## Constraints:

0 <= nums.length <= 3000
-105 <= nums[i] <= 105