-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43fe332
commit a3f13cf
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,27 @@ | ||
""" | ||
Constraints: | ||
- 2 <= nums.length <= 10^4 | ||
- -10^9 <= nums[i] <= 10^9 | ||
- -10^9 <= target <= 10^9 | ||
- Only one valid answer exists. | ||
Time Complexity: O(n²) | ||
- 중첩 반복문을 사용하기 때문 | ||
- 첫 번째 반복문: n번 | ||
- 각각에 대해 두 번째 반복문: n-1, n-2, ... 1번 | ||
- 따라서 총 연산 횟수는 n * (n-1)/2로 O(n²) | ||
Space Complexity: O(1) | ||
- 추가 공간을 사용하지 않음 | ||
- result 리스트는 항상 크기가 2로 고정 | ||
""" | ||
class Solution: | ||
def twoSum(self, nums: List[int], target: int) -> List[int]: | ||
result = [] | ||
|
||
for i in range(len(nums)): | ||
for j in range(i+1, len(nums)): | ||
if nums[j] == target - nums[i]: | ||
return [i, j] | ||
|
||
|