✅링크
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 |