Honestly, this problem might be the easiest one I have solved. Check out the code below, if you get any question, please let me know.
public class Solution {
public int searchInsert(int[] A, int target) {
if(A.length == 0) return 0;
for(int i = 0; i < A.length; i++){
if(A[i] == target) return i;
else{
if(A[i] > target){
return i;
}
}
}
return A.length ;
}
}
No comments:
Post a Comment