Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
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
Tags
more
Archives
Today
Total
관리 메뉴

개발자도전

[LeetCode] 35. Search Insert Position - java 본문

LeetCode

[LeetCode] 35. Search Insert Position - java

도do 2023. 2. 1. 15:30
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
Comments