Skip to content

Commit f38fb79

Browse files
insert position
1 parent b448d22 commit f38fb79

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

searchInsertt.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int searchInsert(int[] nums, int target) {
3+
int index = 0;
4+
if (nums[nums.length-1] < target) { index = nums.length; }
5+
else if (nums[nums.length-1] == target){ index = nums.length-1;}
6+
7+
else {
8+
for (int a =0; a< nums.length-1; a++){
9+
10+
if(nums[a] == target){
11+
index = a;
12+
}
13+
else if ((nums[a]< target) && (nums[a+1] > target) ) { index = a+1;}
14+
15+
}
16+
}
17+
return index;
18+
}
19+
}

0 commit comments

Comments
 (0)