题解 | #寻找牛群中的最高牛#
寻找牛群中的最高牛
https://www.nowcoder.com/practice/df826dd3f9304c61bb6e13fcf16652c3
题目考察的知识点
考察数组
题目解答方法的文字分析
同样不会用二分写出来,直接遍历查找了
本题解析所用的编程语言
使用Java解答
完整且正确的编程代码
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param heights int整型一维数组 * @return int整型 */ public int findPeakElement (int[] heights) { // write code here int res = -1; int index = -1; for (int i = 0; i < heights.length; i++) { if (heights[i] > res) { res = heights[i]; index = i; } } return index; } }