[LeetCode] 2529. Maximum Count of Positive Integer and Negative Integer

Chobby·2025년 11월 13일
1

LeetCode

목록 보기
753/773

😎풀이

  1. nums 순회
    1-1. 0이면 생략
    1-2. 음수 카운트
    1-3. 양수 카운트
  2. 음수와 양수 중 더 높은 수 반환환
function maximumCount(nums: number[]): number {
    let neg = 0
    let pos = 0
    for(const num of nums) {
        if(num === 0) continue
        if(num > 0) pos++
        else neg++
    }
    return Math.max(neg, pos)
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글