File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments