1) Brute Forcetime time complexity O(n^2)
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i, num in enumerate(nums):
rest = target - num
if rest > 0:
for j, num in enumerate(nums):
if i!=j and num == rest:
return [i, j]
2) Hash Map time complexity O(n)
'CODE > 잡기술' 카테고리의 다른 글
HTML Email Template 만들기 (0) | 2023.02.15 |
---|---|
티스토리 다크모드에서 글자가 안 보일 때 (0) | 2023.02.13 |