题目链接:https://leetcode.com/contest/3/problems/is-subsequence/

题目:

s and a string t, check if s is subsequence of t.

s and t. t is potentially a very long (length ~= 500,000) string, and s

"ace" is a subsequence of "abcde" while "aec"Example 1:

s = "abc", t = "ahbgdc"true.Example 2:

s = "axc", t = "ahbgdc"false.

思路:

Longest Substring with At Least K Repeating Characters这道题了。。

算法:

public boolean isSubsequence(String s, String t) {

		if (s.length() == 0)
			return true;
		if (t.length() == 0 && t.length() > s.length())
			return false;

		int i = 0, j = 0;

		// char tc = t.charAt(i);
		while (i < s.length() && j < t.length()) {
			if (i >= s.length())
				return true;
			if (s.charAt(i) == t.charAt(j)) {
				i++;
			}
			j++;
		}

		if (i == s.length())
			return true;
		else
			return false;

	}