Given a string s and a string t, check if s is subsequence of t.
You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string, and s is a short string (< =100). A subsequence of a string is a new string which is formed from the original string by deleting
some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ace" is a subsequence of "abcde" while "aec" is not). Example 1: s = "abc", t = "ahbgdc" Return true. Example 2: s = "axc", t = "ahbgdc" Return
false. 翻译:给你两个字符串,判断s是不是t的子串,s的每个字符在t中的相对顺序不能边,但是可以不连续。比如abc是abcde的子串,也是ahbgdc的子串,但是不是ahbgdc的子串。 这个题我用了一个简单粗暴的方法,最后还超过了93.52%的提交。 算法: 假如我们已经确定s的前i位是t的子串,如果s[i+1]在t中出现那么s可能是t的子串,否则一定不是子串。
LeetCode 392 Is Subsequence
最新推荐文章于 2024-07-10 20:26:14 发布