using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型一维数组 * @return int整型 */ public int findPeakElement(List<int> nums) { // write code here if (nums == null || nums.Count == 0) return -1; if (nums.Count == 1) return 0; return ZBCZ(0, nums.Count - 1, nums); } public int ZBCZ(int nL, int nR, List<int> nums) { if (nL > nR) return -1; int nM = (nL + nR) / 2; int nML = nM - 1 >= 0 ? nums[nM - 1] : int.MinValue; int nMR = nM + 1 <= nums.Count - 1 ? nums[nM + 1] : int.MinValue; if (nums[nM] > nML && nums[nM] > nMR) return nM; int nLR = ZBCZ(nL, nM - 1, nums); if (nLR >= 0) return nLR; int nRR = ZBCZ(nM + 1, nR, nums); if (nRR >= 0) return nRR; else return -1; } }