35. Search Insert Position

easy
最后返回的是nums.length

 

 

 1 class Solution {
 2     public int searchInsert(int[] nums, int target) {
 3         if(nums.length == 0) return 0;
 4         for(int i = 0; i < nums.length; i++) {
 5             if(nums[i] == target) {
 6                 return i;
 7             }else if(nums[i] > target) {
 8                 return i;
 9             }
10         }
11         return nums.length;
12         
13     }
14 }

 

posted @ 2018-09-08 08:05  jasoncool1  阅读(113)  评论(0编辑  收藏  举报