37ms Simple Java Solution


  • 2
        public boolean isSubsequence(String s, String t) {
            if (s.length() > t.length()) return false;
            
            int i = 0, j = 0;
            for (; i < s.length() && j < t.length(); ++j) {
                if (s.charAt(i) == t.charAt(j)) ++i;
            }
            
            return i == s.length();
        }
    

Log in to reply
 

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