TwoSum
주어진 숫자 배열중에 두 수를 더해서 만족 하는 숫자(Target) 되는 Index를 구해라
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
arrLen = len(nums)
for i in range(0, arrLen-1) :
for j in range(1, arrLen) :
if i == j :
continue
sumValue = nums[i] + nums[j]
if sumValue == target :
return [i, j]
Runtime:
48 ms
, faster than62.52%
of Python3 online submissions for Two Sum.
Memory Usage:14.5 MB
, less than45.84%
of Python3 online submissions for Two Sum.
간단하게 이중 for문 돌려서 했는데 가장 기본 적인 방법인듯 하다.
더 최적할 방법이 있는지 찾아봐야됨.