Java 9ms solution


  • 0
    public class Solution {
        public boolean isSubsequence(String s, String t) {
            if (s==null || s.length() == 0) return true;
            if (t==null || t.length() == 0) return false;
            int len = t.length();
            int idx =-1;
            char[] tt = t.toCharArray();
            for (char c: s.toCharArray() ){
                idx++;
                while (idx < len && c != tt[idx] ) idx++;
                if (idx==len) return false;
            }
            return true;
        }
    }
    

Log in to reply
 

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