반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- 스프링부트테스트
- parse
- xcrun: error: invalid active developer path
- easy
- Medium
- java 버전 변경
- java
- tls프로토콜확인
- mysql executequery error
- yum install java
- statement.executequery() cannot issue statements that do not produce result sets.
- ssl이란?
- Java 1.8
- AWS CLI
- log error
- JUnit
- OpenFeign
- xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)
- java 11
- springboot
- java 1.8 11
- No tests found for given includes
- error
- aws
- LeetCode
- mac os git error
- springboottest
- ssl프로토콜확인
- java 여러개 버전
- java version
Archives
- Today
- Total
쩨이엠 개발 블로그
[ Leetcode ] 162. Find Peak Element - Java 본문
728x90
반응형
A peak element is an element that is strictly greater than its neighbors.
Given an integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.
You may imagine that nums[-1] = nums[n] = -∞.
Example 1:
Input: nums = [1,2,3,1]
Output: 2
Explanation: 3 is a peak element and your function should return the index number 2.
Example 2:
Input: nums = [1,2,1,3,5,6,4]
Output: 5
Explanation: Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6.
Constraints:
- 1 <= nums.length <= 1000
- -231 <= nums[i] <= 231 - 1
- nums[i] != nums[i + 1] for all valid i.
Solution
class Solution {
public int findPeakElement(int[] nums) {
int peak = nums[0];
int maxInt = 0;
for(int i=1; i< nums.length; i++){
if(peak < nums[i]){
peak = nums[i];
maxInt = i;
}
}
return maxInt;
}
}
728x90
반응형
'개발 > Programming' 카테고리의 다른 글
[ Leetcode ] 1672. Richest Customer Wealth - Java (0) | 2021.01.28 |
---|---|
[ Leetcode ] 214. Shortest Palindrome - Java (0) | 2021.01.28 |
[ Leetcode ] 1431. Kids With the Greatest Number of Candies - Java (0) | 2021.01.27 |
[ Leetcode ] 28. Implement strStr() - Java (0) | 2021.01.27 |
[ Leetcode ] 1480. Running Sum of 1d Array - Java (0) | 2021.01.27 |
Comments