My java Solution, short


  • 0
    E
    public class Solution {
        public int searchInsert(int[] nums, int target) {
            int i=0;
            int j=nums.length-1;
            while(i<=j){
                int mid = (i+j)/2;
                if(target == nums[mid]){
                    return mid;
                }
                else if(target < nums[mid]){
                    j=mid-1;
                }
                else{
                    i=mid+1;
                }
                
            }
            return i;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.