Skip to content

Commit

Permalink
Solved Is Subsequence
Browse files Browse the repository at this point in the history
  • Loading branch information
1HoWK committed Oct 21, 2024
1 parent 8303949 commit 220dc79
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions leetcode/IsSubsequence.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// LeetCode 392. Is Subsequence

public class isSubsequence{
public boolean isSubsequence(String s, String t) {
if(s.length() == 0){
return true;
}
int sPointer = 0;
int tPointer = 0;

// make sure it iterate until the end
while (tPointer < t.length()) {
if (s.charAt(sPointer) == t.charAt(tPointer)) {
sPointer++;
if (sPointer == s.length()) { // reach the end of s means we have found every characters
return true;
}
}
tPointer++;
}
return false;

}
}

0 comments on commit 220dc79

Please sign in to comment.