-
[LeetCode] # 35. Search Insert Position알고리즘 2022. 4. 24. 15:10
35. Search Insert Position
풀이_#1
이분탐색 사용
class Solution(object): def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ low = 0 high = len(nums) - 1 while (low <= high): mid = low + (high - low)// 2 if nums[mid] == target: return mid elif nums[mid] < target: low = mid + 1 elif nums[mid] > target: high = mid - 1 return low
'알고리즘' 카테고리의 다른 글
[LeetCode] 189. Rotate Array (0) 2022.04.24 [LeetCode] 977. Squares of a Sorted Array (0) 2022.04.24 [LeetCode] 278. First Bad Version (0) 2022.04.24 [LeetCode] 704. Binary Search (0) 2022.04.24 [LeetCode] 234. Palindrome Linked List (0) 2022.04.24