You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
우선 이 질문은 책의 오류나 오타 등에 관한 질문이 아니라서 해도되는건지 잘 모르겠습니다.
만약 안되는거라면 확인 후에 삭제하겠습니다.
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
if len(nums) < 3:
return []
nums.sort()
res = []
for i in range(len(nums)-2):
if i > 0 and nums[i] == nums[i-1]:
continue
left, right = i+1, len(nums)-1
while left < right:
tot = nums[i]+nums[left]+nums[right]
if tot == 0 and sorted([nums[i], nums[left], nums[right]]) not in res:
res.append(sorted([nums[i], nums[left], nums[right]]))
left += 1
right -= 1
elif tot < 0:
left += 1
elif tot > 0:
right -= 1
else: # tot이 0이고 res에 이미 중복된 배열이 있을 때 무한루프를 방지하기위함
left += 1
right -= 1
return res
이건 제가 구현한 풀이이고 릿코드에 제출하면 time limit이 나오는데 제가 봤을 때 시간복잡도가 책이랑 차이가 왜 많이 나는지
잘 모르겠는데 이유를 알 수 있을까요? 파이참에서 오류 케이스를 돌려본 결과 답이 나오긴하는걸보면 알고리즘은 맞는거같은데 어떤거때매 시간복잡도 차이가 많이 나는건지 잘 모르겠습니다.
The text was updated successfully, but these errors were encountered:
우선 이 질문은 책의 오류나 오타 등에 관한 질문이 아니라서 해도되는건지 잘 모르겠습니다.
만약 안되는거라면 확인 후에 삭제하겠습니다.
class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
if len(nums) < 3:
return []
이건 제가 구현한 풀이이고 릿코드에 제출하면 time limit이 나오는데 제가 봤을 때 시간복잡도가 책이랑 차이가 왜 많이 나는지
잘 모르겠는데 이유를 알 수 있을까요? 파이참에서 오류 케이스를 돌려본 결과 답이 나오긴하는걸보면 알고리즘은 맞는거같은데 어떤거때매 시간복잡도 차이가 많이 나는건지 잘 모르겠습니다.
The text was updated successfully, but these errors were encountered: