일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Decorator
- 프로그래머스
- 43. Multiply Strings
- Convert Sorted List to Binary Search Tree
- data science
- Regular Expression
- Python Implementation
- 715. Range Module
- Python
- shiba
- 시바견
- 컴퓨터의 구조
- 파이썬
- LeetCode
- kaggle
- Generator
- Protocol
- 30. Substring with Concatenation of All Words
- t1
- 밴픽
- 운영체제
- iterator
- Substring with Concatenation of All Words
- DWG
- Python Code
- Class
- concurrency
- attribute
- 109. Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
Archives
- Today
- Total
Scribbling
LeetCode: 15. 3Sum 본문
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
nums.sort()
N, ret = len(nums), []
for i in range(N):
if i > 0 and nums[i] == nums[i-1]:
continue
target = -nums[i]
l, r = i + 1, N - 1
while l < r:
if nums[l] + nums[r] == target:
ret.append([nums[i], nums[l], nums[r]])
l += 1
while l < r and nums[l] == nums[l-1]:
l += 1
elif nums[l] + nums[r] > target:
r -= 1
else:
l += 1
return ret
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 17. Letter Combinations of a Phone Number (0) | 2021.08.21 |
---|---|
LeetCode: 16. 3Sum Closest (0) | 2021.08.21 |
LeetCode: 11. Container With Most Water (1) | 2021.08.17 |
LeetCode: 8. String to Integer (atoi) (0) | 2021.08.16 |
LeetCode: 6. ZigZag Conversion (0) | 2021.08.16 |