30ms Java Recursive.


  • 0
    U
    public class Solution {
    
    public boolean isSubsequence(String s, String t) {
        return helper(s, t, 0, 0);
    }
    
    public boolean helper(String s, String t, int s_start, int t_start){
        if(s_start == s.length()){
            return true;
        }else if(t_start == t.length()){
            return false;
        }
        while(s.charAt(s_start) != t.charAt(t_start++)){
            if(t_start == t.length()){
                return false;
            }
        }
        return helper(s, t, s_start + 1, t_start);
    }
    

    }


Log in to reply
 

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