Easy Java Solution with two pointers


  • 0
    B
    class Solution {
        public boolean isSubsequence(String s, String t) {
            
            if(s == null){
                return false;
            }
            
            if(t == null){
                return true;
            }
            
            int post= 0;
            int poss= 0;
            
            while(post < t.length() && poss < s.length()){
                if(t.charAt(post) == s.charAt(poss)){
                    post++;
                    poss++;
                }else{
                    post++;
                }
            }
            
            
            if(poss == s.length()){
                return true;
            }
            
            return false;
        }
    }
    

Log in to reply
 

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