LeetCode problem#392
Is Subsequence
Solved in 1 languageJava
Solution
15 lines
1class Solution {
2 public boolean isSubsequence(String s, String t) {
3 int j = 0;
4
5 for (int i = 0; i < t.length() && j < s.length(); i++)
6 {
7 if (t.charAt(i) == s.charAt(j))
8 {
9 j++;
10 }
11 }
12
13 return j >= s.length();
14 }
15}Want a walkthrough of this Java solution?
Get a step-by-step explanation of the idea behind the code.
Problem statements belong to LeetCode and are on leetcode.com. We're not affiliated with LeetCode.