[LeetCode] 2148. Count Elements With Strictly Smaller and Greater Elements

Chobby·5일 전
1

LeetCode

목록 보기
676/710

😎풀이

  1. 최댓값 계산
  2. 최솟값 계산
  3. nums 순회
    3-1. 최댓값 혹은 최솟값과 동일한 경우 조건을 만족하지 못함
    3-2. 둘 다 아닌 경우 이 수보다 큰 수와 작은 수를 두고 있으므로 카운트
  4. 자신의 수보다 크고 작은 수를 보유한 값들의 수를 반환
function countElements(nums: number[]): number {
    const max = Math.max(...nums)
    const min = Math.min(...nums)
    let count = 0
    for(const num of nums) {
        if(num === max) continue
        if(num === min) continue
        count++
    }
    return count
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글