1. 程式人生 > >LeetCode: 792. Number of Matching Subsequences

LeetCode: 792. Number of Matching Subsequences

class Solution {
    public int numMatchingSubseq(String S, String[] words) {
		return (int)Arrays.stream(words)
			.filter(word -> {
				int currentLoc = 0;
				byte[] bytes = word.getBytes();
				for(int i =0; i < bytes.length; i++) {
					currentLoc = S.indexOf(bytes[i], currentLoc);
					if(currentLoc == -1) {
						return false;
					}
					currentLoc++;
				}
				return true;
			})
			.count();
	}
}