[LeetCode] 334. Increasing Triplet Subsequence

Chobby·2025년 3월 17일
1

LeetCode

목록 보기
296/427

😎풀이

  1. first 선언
  2. second 선언
  3. nums 순회
    3-1. first 초과 수 탐색
    3-2. second 초과 수 탐색
    3-3. 증가하는 세개의 서브시퀀스 확인 시 true 반환
  4. 미확인 시 false 반환
function increasingTriplet(nums: number[]): boolean {
    let first = Infinity
    let second = Infinity
    for(const num of nums) {
        if(num <= first) first = num
        else if(num <= second) second = num
        else return true
    }
    return false
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글