题解 | #旋转位置的特定牛#
旋转位置的特定牛
https://www.nowcoder.com/practice/4872ba1fef224bd382b49a5958d996ab
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param nums int整型一维数组
* @param target int整型
* @return int整型
*/
public static int search (int[] nums, int target) {
// write code here
int start = 0;
int end = nums.length - 1;
while (start <= end) {
int mid = (start + end) / 2;
if (nums[mid] > target) {
start++;
} else if (nums[mid] < target) {
end--;
} else {
return mid;
}
}
return -1;
}
}
本题考察的知识点是二分查找,所用编程语言是java。
直接使用二分查找就可以通过此题的示例
联想公司福利 1502人发布