Java StringBuffer solution beats 91%


  • 0
    A
    public class Solution {
        public boolean isSubsequence(String s, String t) {
            StringBuffer tb = new StringBuffer(t);
            for(int i=0; i<s.length(); i++){
                int idx = tb.indexOf(Character.toString(s.charAt(i)));
                if(idx<0){
                    return false;
                }
                tb.delete(0,idx+1);
            }
            return true;
        }
    }
    

Log in to reply
 

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