Leetcode - 392. Is Subsequence

例子:

Example 1:

s="abc",t="ahbgdc"

Return true.

Example 2:

s="axc",t="ahbgdc"

Return false.



解法:two pointer

base:

如果w1 的pointer等于length of w1, return true

如果w2 的pointer等于length of w2,return false

------

step

对比字母,如果两个单词 w1[0] == w2[0],两个单词同时推进一个

如果两个cha不相等 ,那么就只推进w2的pointer add1,


代码


Leetcode - 392. Is Subsequence_第1张图片

你可能感兴趣的:(Leetcode - 392. Is Subsequence)