[LeetCode] 3065. Minimum Operations to Exceed Threshold Value I

Chobby·3일 전

LeetCode

목록 보기
847/853

😎풀이

  1. nums를 오름차 순 정렬
  2. 각 요소를 순회하며, k 미만인 수 카운트
  3. nums의 모든 수가 k 이상이 되도록 하는 필요 제거 연산의 수 반환
function minOperations(nums: number[], k: number): number {
    const sorted = nums.toSorted((a, b) => a - b)
    let operation = 0
    for(const num of sorted) {
        if(num >= k) break
        operation++
    }
    return operation
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글