Java Recursive Solution

  • 0
        public boolean isSubsequence(String s, String t) {
            if (s.length() > t.length()) return false;
            return helper(s, t, 0, 0);
        public boolean helper(String s, String t, int sPointer, int tPointer) {
            if (sPointer == s.length()) return true;
            if (tPointer == t.length()) return false;
            for (int i = tPointer; i < t.length(); i++) {
                if (s.charAt(sPointer) == t.charAt(i)) {
                    if (helper(s, t, sPointer+1, i+1)) return true;
            return false;

Log in to reply

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