我的LeetCode代码仓:https://github.com/617076674/LeetCode
原题链接:https://leetcode-cn.com/problems/find-peak-element/description/
题目描述:
知识点:二分查找法
思路一:暴力破解法
逐个遍历数组中的元素即可。
时间复杂度是O(n),其中n为数组中的元素个数。空间复杂度是O(1)。
JAVA代码:
public class Solution {
public int findPeakElement(int[] nums) {
if(1 == nums.length){
return 0;
}
for(int i = 0; i < nums.length; i++){
if(i == 0){
if(nums[0] > nums[1]){
return 0;
}
}else if(i &