
-Code
class Solution {
public int searchInsert(int[] nums, int target) {
for(int i = 0; i < nums.length; i++) {
// 현제 값보다 작거나 같으면 index 반환
if (nums[i] >= target) return i;
}
// 조건에 걸리지 않으면 마지막 index이므로 길이만큼 반환
return nums.length;
}
}'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [LeetCode/Java] 66. Plus One (0) | 2025.11.21 |
|---|---|
| [LeetCode/Java] 58. Length of Last Word (0) | 2025.11.20 |
| [LeetCode/Java] 28. Find the Index of the First Occurrence in a String (0) | 2025.11.20 |
| [백준/Java] 2252번 줄 세우기 (0) | 2025.11.20 |
| [백준/Java] 34750번 추석은 언제나 좋아 (0) | 2025.11.20 |