using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @param target int整型 * @return int整型 */ public int search (List<int> nums, int target) { if(nums == null) return -1; int right = 0; int left = nums.Count - 1; while(right <= left){ int cur = right + (left - right)/2; if(nums[cur] < target) right = cur + 1; else if(nums[cur] == target) return cur; else left = cur - 1; } //if(nums[left] == target) return left; return -1; } }