Java simple


  • 0
    Z

    class Solution {
    public int searchInsert(int[] nums, int target) {
    int len=nums.length;
    int pos =0;
    for(int i=0;i<len;i++){
    if(target<=nums[i]){
    pos=i;
    break;
    }
    else if(target>nums[i]&&i==len-1||target>nums[i]&&target<=nums[i+1]){
    pos=i+1;
    break;
    }
    }
    return pos;
    }
    }


Log in to reply
 

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