[LeetCode] Two Sum
1. ๋ฌธ์ : Link
๋ฐฐ์ด ์ ๋ ์๋ฅผ ํฉํ์๋ target์ด ๋์ค๋ ๊ฒฝ์ฐ, ๊ทธ๋์ ์ธ๋ฑ์ค๋ฅผ return
2. ํ์ด
๋ชจ๋ ๋ฐฐ์ด์ ์ํํ๋ brute force ๋ฅผ ์ ์ฉํด์ target๊ฐ์ด ๋ง์กฑ๋๋ ์ธ๋ฑ์ค๊ฐ ๋์ค๋ฉด ๋ฐ๋ก ๋ต์ผ๋ก return
3. ์ฝ๋
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(len(nums)):
for j in range(i+1, len(nums)):
if nums[i] + nums[j] == target:
return [i,j]
'๐ป Coding Problems Solving > Array | String | Loop' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[LeetCode] Contains Duplicate (0) | 2022.07.09 |
---|---|
[LeetCode] Best Time to Buy and Sell (0) | 2022.07.03 |
[BOJ 1789] ์๋ค์ ํฉ (0) | 2022.06.26 |
[BOJ 1978] ์์์ฐพ๊ธฐ (0) | 2022.06.22 |
[BOJ 2693] N๋ฒ์งธ ํฐ ์ (0) | 2022.06.22 |
์ต๊ทผ๋๊ธ