| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- kaggle
- Python Code
- data science
- 715. Range Module
- 파이썬
- Protocol
- concurrency
- iterator
- Convert Sorted List to Binary Search Tree
- Class
- 43. Multiply Strings
- Regular Expression
- shiba
- 컴퓨터의 구조
- 밴픽
- 315. Count of Smaller Numbers After Self
- 프로그래머스
- t1
- Generator
- 109. Convert Sorted List to Binary Search Tree
- Decorator
- Python Implementation
- attribute
- Python
- DWG
- 시바견
- 30. Substring with Concatenation of All Words
- Substring with Concatenation of All Words
- 운영체제
- LeetCode
Archives
- Today
- Total
Scribbling
35. Search Insert Position 본문
Binary Search 살짝만 바꿔주자
class Solution:
def searchInsert(self, nums: List[int], target: int) -> int:
return self.binary_search(nums, 0, len(nums)-1, target)
def binary_search(self, nums, l, r, target):
if l == r:
if target <= nums[l]:
return l
else:
return l + 1
mid_idx = (l + r) // 2
mid = nums[mid_idx]
if target <= mid:
return self.binary_search(nums, l, mid_idx, target)
else:
return self.binary_search(nums, mid_idx+1, r, target)'Computer Science > Coding Test' 카테고리의 다른 글
| 33. Search in Rotated Sorted Array (0) | 2021.09.11 |
|---|---|
| LeetCode: 31. Next Permutation (0) | 2021.09.09 |
| LeetCode: 49. Group Anagrams (0) | 2021.09.08 |
| LeetCode: 41. First Missing Positive (0) | 2021.09.08 |
| LeetCode: 47. Permutations II (0) | 2021.09.07 |