Easy understanding Java solution, 12ms.


  • 0
    Y
        public boolean isSubsequence(String s, String t) {
            char[] sa = s.toCharArray();
            char[] ta = t.toCharArray();
            label:
            for (int sIndex = 0, tIndex = 0; sIndex < sa.length; ++sIndex) {
                while (tIndex < ta.length)
                    if (sa[sIndex] == ta[tIndex++]) continue label;
                return false;
            }
            return true;
        }
    

Log in to reply
 

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