๐ป Coding Problems Solving/Array | String | Loop
[LeetCode] Two Sum
[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]
2022. 6. 30. 04:13
์ต๊ทผ๋๊ธ