• 문제 링크
Search Insert Position - LeetCode
Can you solve this real interview question? Search Insert Position - 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 w
leetcode.com
• 풀이 코드
public class Solution {
public int searchInsert(int[] nums, int target) {
int l = 0, r = nums.length - 1, m = r >> 1;
while (l <= r) {
if (target <= nums[m]) r = m - 1;
else l = m + 1;
m = (r + l) >> 1;
}
return l;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 66. Plus One - Java (0) | 2026.05.20 |
|---|---|
| [LeetCode] 58. Length of Last Word - Java (0) | 2026.05.19 |
| [LeetCode] 24. Swap Nodes in Pairs - Java (0) | 2026.05.17 |
| [LeetCode] 28. Find the Index of the First Occurrence in a String - Java (0) | 2026.05.16 |
| [LeetCode] 27. Remove Element - Java (0) | 2026.05.15 |
댓글