โœ๏ธ ์ฝ”ํ…Œ ์ค€๋น„/Binary Search

โœ๏ธ ์ฝ”ํ…Œ ์ค€๋น„/Binary Search

[LeetCode] 167. Two Sum II - Input Array Is Sorted

์ž…๋ ฅ ์˜ˆ์‹œ ํ’€์ด ์–ธ์–ด Python ํ’€์ด ๋ฐฉ๋ฒ• ์ •๋ ฌ๋œ ๋ฐฐ์—ด์—์„œ target์„ ๋งŒ์กฑํ•˜๋Š” ๋‘ ์›์†Œ์˜ index๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฌธ์ œ์˜€๋‹ค. ์˜ค๋ฆ„์ฐจ์ˆœ์„ ์ •๋ ฌ๋œ ๋ฐฐ์—ด์ด์—ˆ๊ธฐ์— BST ๋ฌธ์ œ๋ผ๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค. ์–ด๋ ต์ง€ ์•Š๊ฒŒ ํ•ด๊ฒฐํ–ˆ๋‹ค. ์ฝ”๋“œ class Solution: def twoSum(self, numbers: List[int], target: int) -> List[int]: start = 0 end = len(numbers) - 1 while start target: end -= 1 elif mid < target: start += 1 else: return [start + 1, end + 1] ๊ฒฐ๊ณผ

kodo_o
'โœ๏ธ ์ฝ”ํ…Œ ์ค€๋น„/Binary Search' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก