LeetCode [JS] > 392. Is Subsequence

2025. 3. 27. 23:30·🔒Algorithm

✅링크

https://leetcode.com/problems/is-subsequence/description/

✅풀이

쉽게 문제 풀 수 있다. 시간 복잡도는 O(n) 이다. 

/**
 * @param {string} s
 * @param {string} t
 * @return {boolean}
 */
var isSubsequence = function(s, t) {
    
    let sIdx = 0, tIdx = 0

    while(sIdx<s.length && tIdx<t.length){
        if(s[sIdx]===t[tIdx]){
            ++sIdx
            ++tIdx
        }else{
            ++tIdx
        }
    }
    return sIdx === s.length ? true:false
};

//  시간 복잡도  log(t.lenght)

'🔒Algorithm' 카테고리의 다른 글

LeetCode > 2022. Convert 1D Array Into 2D Array  (0) 2025.03.29
LeetCode > 2591. Distribute Money to Maximum Children  (0) 2025.03.28
LeetCode [JS] > Third Maximum Number  (0) 2025.03.26
HackerRank > big-sorting  (0) 2025.03.22
LeetCode[JS] > 2718. Sum of Matrix After Queries  (0) 2025.03.15
'🔒Algorithm' 카테고리의 다른 글
  • LeetCode > 2022. Convert 1D Array Into 2D Array
  • LeetCode > 2591. Distribute Money to Maximum Children
  • LeetCode [JS] > Third Maximum Number
  • HackerRank > big-sorting
devWarrior
devWarrior
  • devWarrior
    devWarrior
    devWarrior
  • 전체
    오늘
    어제
    • 🧩Dev (263)
      • ⭐FE (34)
      • 🔒Algorithm (155)
      • ➕Etc. (11)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 글쓰기
    • 관리
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    js
    프로그래머스
    Algorithm
    DFS
    실버2
    프론트엔드
    BFS
    FE
    nodejs
    node.js
    자바스크립트
    오블완
    구현
    javascript
    Easy
    알고리즘
    Lv2
    백준
    leetcode
    그리디
    실버4
    티스토리챌린지
    실버1
    실버3
    코테
    자스
    코딩테스트
    골드5
    react
    dp
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
devWarrior
LeetCode [JS] > 392. Is Subsequence
상단으로

티스토리툴바