Skip to content

Commit 8f4761e

Browse files
authored
java solution of the leetcode problem number 35
1 parent 3ff1f5c commit 8f4761e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

leetcode/search_insert_position

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#Java Solution
2+
3+
class Solution {
4+
public int searchInsert(int[] nums, int target) {
5+
6+
int size = nums.length;
7+
//If element is present in the array
8+
for(int i=0;i<size;i++){
9+
if(nums[i] == target)
10+
return i;
11+
}
12+
int j=0;
13+
//If element is not there in the array
14+
for(int i=0;i<size;i++){
15+
if(nums[i] < target){
16+
j++;
17+
}else{
18+
break;
19+
}
20+
}
21+
return j;
22+
23+
}
24+
}

0 commit comments

Comments
 (0)