2ms Java solution


  • 0
    Y
    public boolean isSubsequence(String s, String t) {
            int start = 0;
            int index = 0;
            boolean result = true;
            for (char i:s.toCharArray()){
                index = t.indexOf(i, start);
                if (index==-1){
                    result = false;
                    break;
                }
                start = index+1;
            }
            return result;
        }
    

Log in to reply
 

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