2ms 3 lines Java using indexOf


  • 0
    W
    public boolean isSubsequence(String s, String t) {
        for (int sIdx = 0, tIdx = -1, len = s.length(); sIdx < len;)
            if ((tIdx = t.indexOf(s.charAt(sIdx++), ++tIdx)) == -1) return false;
        return true;
    }

Log in to reply
 

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