Skip to content

Commit 502b345

Browse files
committed
add case
1 parent dc94432 commit 502b345

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package search_insert_position;
2+
3+
class Solution {
4+
public int searchInsert(int[] nums, int target) {
5+
int index = 0;
6+
for (int i = 0; i < nums.length; i++) {
7+
if (nums[i] >= target) {
8+
index = i;
9+
break;
10+
}
11+
}
12+
13+
if (nums.length > 0 && index == 0 && nums[nums.length - 1] < target) {
14+
return nums.length;
15+
}
16+
17+
return index;
18+
}
19+
}
20+
21+
public class search_insert_position {
22+
public static void main(String[] args) {
23+
Solution solution = new Solution();
24+
System.out.println(solution.searchInsert(new int[] { 2, 7, 11, 15 }, 9));
25+
}
26+
}

0 commit comments

Comments
 (0)