Java simple recursive solution - 17ms


  • 0
    R
    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;
    
            if (!t.contains(s.substring(0,1))){
                return false;
            }
            int k = t.indexOf(s.charAt(0));
            return isSubsequence(s.substring(1), t.substring(k + 1));
        }
    }
    

Log in to reply
 

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