Simple java solution


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

Log in to reply
 

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