Given two strings s and t, return true if s is a subsequence of t, or false otherwise.
A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without distu
class Solution {
public boolean isSubsequence(String s, String t) {
if (s.length() ==0) return true;
int spoint = 0;
int tpoint = 0;
while (tpoint < t.length()) {
if (t.charAt(tpoint) == s.charAt(spoint)) {
spoint++;
if (spoint == s.length()) return true;
}
tpoint++;
}
return false;
}
}
No comments:
Post a Comment