Double loop Java solution


  • 0
    G
        public static boolean isSubsequence(String s, String t) {
        	int j=0;//mark the index in String t, start from pre position
    	int len=0;//record the len of matched letters
        	for(int i=0;i<s.length();i++){
        		
        		while(j<t.length()){
        			if(s.charAt(i)==t.charAt(j++)){
        				len++;
        				break;
        			}
        		}
        	}
        	if(len!=s.length()){
        		return false;
        	}
        	return true;
        }
    

Log in to reply
 

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