Loading
Leetcode / 392. Is Subsequence

Pick a programming language:

Here is the source code for the solution to this problem.

class Solution {
  public boolean isSubsequence(String s, String t) {
      int j = 0;

      for (int i = 0; i < t.length() && j < s.length(); i++)
      {
          if (t.charAt(i) == s.charAt(j))
          {
              j++;
          }
      }

      return j >= s.length();
  }
}
Did you like the lesson? 😆👍
Consider a donation to support our work: