
-Code
class Solution {
public boolean isSubsequence(String s, String t) {
int sLength = s.length();
int idx = 0;
// t를 돌면서 비교
for (char ch : t.toCharArray()) {
// s의 전체 길이가 현재 인덱스와 같으면 true
if (sLength == idx) {
return true;
}
if (s.charAt(idx) == ch) {
idx++;
}
}
// t의 마지막 단어가 s의 마지막 단어가 같은 경우 검증
return idx == s.length();
}
}'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [LeetCode/Java] Find the Highest Altitude (0) | 2025.12.31 |
|---|---|
| [LeetCode/Java] Maximum Average Subarray I (0) | 2025.12.31 |
| [LeetCode/Java] Move Zeroes (0) | 2025.12.31 |
| [LeetCode/Java] Two Sum (0) | 2025.12.31 |
| [LeetCode/Java] Valid Anagram (0) | 2025.12.31 |