[LeetCode] 674. Longest Continuous Increasing Subsequence

Chobby·2025년 4월 27일
1

LeetCode

목록 보기
381/427

😎풀이

  1. maxLength: 증가하는 subArray 요소의 최대 길이
  2. curLength: 증가하는 subArray 현재 길이
  3. curGap: 현재 요소와 이전 요소의 차
  4. 증가하지 않는다면 길이를 초기화하고, 증가한다면 curLength를 증가시키며 최대 길이와 비교
  5. 탐색된 subArray 중 최대 길이 반환
function findLengthOfLCIS(nums: number[]): number {
    let maxLength = 1
    let curLength = 1
    for(let i = 1; i < nums.length; i++) {
        const curGap = nums[i] - nums[i - 1]
        if(curGap <= 0) {
            curLength = 1
            continue
        }
        curLength++
        maxLength = Math.max(maxLength, curLength)
    }
    return maxLength
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글