Simple Solution


  • 0
    S
    class Solution {
        public boolean isSubsequence(String s, String t) {
            if(s.equals("")) return true;
            if(t.equals("") && !s.equals("")) return false;
            char[] tArr = t.toCharArray();
            char[] sArr = s.toCharArray();
            int tlo = 0, slo = 0;
            int thi = tArr.length-1, shi = sArr.length-1;
            while(thi>=tlo) {
                if(tArr[thi] == sArr[shi]) shi--;
                if(tArr[tlo] == sArr[slo]) slo++;
                thi--;
                tlo++;
                if(shi<slo) return true;
            }
            return false;
        }
    }
    

Log in to reply
 

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