Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
안녕하세요
class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: result = [] nums.sort() for i in range (len(nums)-2) : if i > 0 and nums[i] == nums[i-1] : # 중복일 경우 pass continue left, right = i +1, len(nums)-1 while left < right : sum = nums[left] + nums[right] + nums[i] if sum > 0 : right -=1 if sum < 0 : left += 1 # if 면 틀린다 else : # sum == 0 일 때 result.append([nums[i],nums[left],nums[right]]) while left < right and nums[left] == nums[left+1] : left+=1 # if가 아니라 while while left < right and nums[right] == nums[right-1] : right-=1 left += 1 right -= 1 return result
class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: result = [] nums.sort() for i in range (len(nums)-2) : if i > 0 and nums[i] == nums[i-1] : # 중복일 경우 pass continue left, right = i +1, len(nums)-1 while left < right : sum = nums[left] + nums[right] + nums[i] if sum > 0 : right -=1 elif sum < 0 : left += 1 # if 면 틀린다 else : # sum == 0 일 때 result.append([nums[i],nums[left],nums[right]]) while left < right and nums[left] == nums[left+1] : left+=1 # if가 아니라 while while left < right and nums[right] == nums[right-1] : right-=1 left += 1 right -= 1 return result
처음 코드 처럼 if를 두개 하면 틀리고 두번째 if를 elif로 바꾸면 맞습니다가 나옵니다. 그런데 이 둘이 차이가 나는 이유를 모르겠어서 여쭤보고 싶습니다!
The text was updated successfully, but these errors were encountered:
else 절은 sum == 0 일 때 일어나야 하는데... 위 코드는 sum > 0 때, 아래 if의 else 절이 실행될 것 같아요.
Sorry, something went wrong.
sum <0 일 때, else 가 실행된다는 말씀이시죠?
문제 풀이에 앞서 어떤 차이가 있는지 확실히 숙지하는게 좋을거 같습니다. https://www.w3resource.com/python/python-if-else-statements.php 여기에 설명이 아주 잘 나와 있네요. 이 설명을 확실히 이해하면 문제 풀이도 자연스럽게 이해될거 같습니다.
넵 감사합니다!
No branches or pull requests
안녕하세요
처음 코드 처럼 if를 두개 하면 틀리고 두번째 if를 elif로 바꾸면 맞습니다가 나옵니다.
그런데 이 둘이 차이가 나는 이유를 모르겠어서 여쭤보고 싶습니다!
The text was updated successfully, but these errors were encountered: