-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
} |