Leetcode 162 Find Peak Element 查找峰值元素(极大值)

原题地址

https://leetcode.com/problems/find-peak-element/

题目描述

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.
给出一个不含重复元素的数组num,找出其中的峰值元素并返回其索引(下标)值.

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] = -∞.
假设nums[-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.
例如,在数组 [1, 2, 3, 1] 中,3是峰值元素,你的函数需要返回下标2.

spoilers.
挑战.
Note:
注意:

Your solution should be in logarithmic complexity.
你的方法的时间复杂度需要为对数级别复杂度

解题思路一 O(n) 比较次数2n

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值