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》

    原文作者:KkevinZz
    原文地址: https://www.jianshu.com/p/5575a352f8e4
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞