LeetCode: 392. Is Subsequence

题目: LeetCode: 392. Is Subsequence(https://leetcode.com/problems/is-subsequence/description/)

class Solution {
	public boolean isSubsequence(String s, String t) {

		int currentLoc = 0;
		byte[] bytes = s.getBytes();
		for (int i = 0; i < bytes.length; i++) {
			currentLoc = t.indexOf(bytes[i], currentLoc);
			if (currentLoc == -1) {
				return false;
			}
			currentLoc++;
		}
		return true;
	}
}

猜你喜欢

转载自blog.csdn.net/majinliang1234/article/details/82805013