Skip to content

Commit 39b1c5a

Browse files
author
shrinathjoshi
committed
Updated solution to day 9 of June Leetcode Challenge
1 parent 1a611da commit 39b1c5a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

0 commit comments

Comments
 (0)