国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

162. Find Peak Element

2019-11-06 07:25:03
字體:
供稿:網(wǎng)友

A peak element is an element that is greater than its neighbors.

Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.

The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.

You may imagine that num[-1] = num[n] = -∞.

For example, in array [1, 2, 3, 1], 3 is a peak element and your function should return the index number 2.

click to show spoilers.

Note: Your solution should be in logarithmic complexity.

public class Solution { public int findPeakElement(int[] nums) { if(nums == null || nums.length == 0) return 0; int left = 0; int right = nums.length-1; while (left < right) { int mid1 = (left + right) / 2; int mid2 = mid1 + 1; if(nums[mid2] > nums[mid1]) left = mid2; else right = mid1; } return left; }}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 灵武市| 乌兰县| 青阳县| 河津市| 平遥县| 虞城县| 阳信县| 尼勒克县| 内黄县| 芦山县| 彝良县| 威信县| 比如县| 新巴尔虎右旗| 南通市| 通辽市| 合水县| 郴州市| 郑州市| 工布江达县| 新邵县| 榆树市| 周口市| 健康| 南平市| 元阳县| 花莲市| 梨树县| 上虞市| 二连浩特市| 临朐县| 奉化市| 三门峡市| 易门县| 泽普县| 蒲城县| 建瓯市| 商南县| 乌兰浩特市| 蓝田县| 喀什市|