JAVA Solution. Simple and Easy understood


  • 1
    public class Solution {
    public boolean isSubsequence(String s, String t) {
        int sLen = s.length();
        int tLen = t.length();
        int sPtr = 0, tPtr = 0;
        while (sPtr < sLen && tPtr < tLen){
            if (s.charAt(sPtr) == t.charAt(tPtr)){
                sPtr++; tPtr++;
            } else
                tPtr++;
            if (sPtr == sLen) return true;
            if (tPtr == tLen) return false;
        }
        return sLen <= tLen;
        
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.