My 2ms Java Solution


  • 0
    S
    public class Solution {
        public boolean isSubsequence(String s, String t) {
            if(s == null || t == null){
                return false;
            }
            if(t.length() < s.length()){
                return false;   
            }
            int index = -1;
            for(int i = 0; i < s.length(); i++){
                index = t.indexOf(s.charAt(i), index + 1);
                if(index == -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.