File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
June Challenge/com/leetcode/JuneChallenge/week2 Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .leetcode .JuneChallenge .week2 ;
2+
3+ public class IsSubsequence {
4+
5+ public boolean isSubsequence (String s , String t ) {
6+ // Base Condition
7+ if (s .length () == 0 && t .length () != 0 )
8+ return true ;
9+
10+ if (s .length () > t .length ())
11+ return false ;
12+
13+ int firstPointer = 0 ;
14+ int secondPointer = 0 ;
15+
16+ while (firstPointer < s .length () && secondPointer < t .length ()) {
17+
18+ if (s .charAt (firstPointer ) == t .charAt (secondPointer )) {
19+ firstPointer ++;
20+ secondPointer ++;
21+ } else
22+ secondPointer ++;
23+ }
24+
25+ return firstPointer == s .length ();
26+ }
27+
28+ public static void main (String [] args ) {
29+
30+ String s = "abc" , t = "ahbgdc" ;
31+ System .out .println (new IsSubsequence ().isSubsequence (s , t ));
32+ }
33+
34+ }
You can’t perform that action at this time.
0 commit comments