개발자도전
[LeetCode] 35. Search Insert Position - java 본문
728x90
[문제]
Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.
You must write an algorithm with O(log n) runtime complexity.
배열 중 target과 같은 값이 있다면 그 값을 return 시키고 그렇지 않다면 그 값이 어디에 들어갈 지 알아내라.
[입출력 예]
Example 1:
Input: nums = [1,3,5,6], target = 5
Output: 2
Example 2:
Input: nums = [1,3,5,6], target = 2
Output: 1
Example 3:
Input: nums = [1,3,5,6], target = 7
Output: 4
[답]

728x90
'LeetCode' 카테고리의 다른 글
| [LeetCode] 20. Valid Parentheses (0) | 2023.02.03 |
|---|---|
| [LeetCode] 58. Length of Last Word (0) | 2023.02.02 |
| [LeetCode] Valid Mountain Array (0) | 2023.01.31 |
| [LeetCode] Check If N and Its Double Exist (0) | 2023.01.28 |
| [LeetCode] Remove Duplicates from Sorted Array (0) | 2023.01.26 |
Comments