标签:length targe write sorted return ret while integer result
question:
code:
public class Solution { /** * @param nums: An integer array sorted in ascending order * @param target: An integer * @return an integer */ public int findPosition(int[] nums, int target) { // Write your code here int start = 0; int end = nums.length - 1; int mid = 0; while(start <= end) { mid = (start + end) / 2; if(target < nums[mid]) { end = mid - 1; } else if(target > nums[mid]) { start = mid + 1; } else { return mid; } } return -1; } }
result:
标签:length targe write sorted return ret while integer result
原文地址:http://www.cnblogs.com/jizuiku/p/7513701.html