Java Solution O(t)


  • 0
    public class Solution {
        public boolean isSubsequence(String s, String t) {
            if (s.length() > t.length()){
                return false;
            }
            
            int sPtr = 0;
            for (int tPtr = 0; tPtr < t.length() && sPtr < s.length(); ++tPtr){
                if (s.charAt(sPtr) == t.charAt(tPtr)){
                    ++sPtr;
                } 
            }
            
            return sPtr == s.length();
            
        }
    }
    

Log in to reply
 

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