Easy Understand Java Two Point Solution


  • 0
    W
    public boolean isSubsequence(String s, String t) {
            int index1 = 0, index2 = 0;
            while (index1 < s.length() && index2 < t.length()) {
                if (s.charAt(index1) == t.charAt(index2)) {
                    index1++;
                    index2++;
                } else {
                    index2++;
                }
            }
            return index1 == s.length() && index2 <= t.length();
        }
    

Log in to reply
 

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