leetcode - find peak element(kotlin)

silver·2021년 7월 14일
0

level - medium

[문제 내용]
배열에서 양옆의 원소들보다 큰 원소의 index를 반환

[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.

[해결 방법]
그냥 가장 큰 원소 찾았다..
이렇게 푸는거 맞나..?

class Solution {
    fun findPeakElement(nums: IntArray): Int {
        return nums.indexOf(nums.max()!!)
    }
}

0개의 댓글