Very simple Java


  • 0
    3
    class Solution {
        public boolean isSubsequence(String s, String t) {
            if(s.length()==0)return true;
            int last = -1;
            for(int i=0;i<s.length();i++){
                if(t.indexOf(s.charAt(i),last+1)>-1)last = t.indexOf(s.charAt(i),last+1);
                else return false;
            }
            return true;
        }
    }

Log in to reply
 

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