美文网首页
392. Is Subsequence

392. Is Subsequence

作者: becauseyou_90cd | 来源:发表于2018-07-22 00:09 被阅读0次

    https://leetcode.com/problems/is-subsequence/description/
    解题思路:

    1. 判断s和t的字符是否相等

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

        int sLen = s.length(), tLen = t.length(), sIndex = 0;
        for(int i = 0; i < tLen && sIndex < sLen; i++){
           if(t.charAt(i) == s.charAt(sIndex)){
               sIndex++;
           }
        }
        return sIndex == sLen;
    }
    

    }

    相关文章

      网友评论

          本文标题:392. Is Subsequence

          本文链接:https://www.haomeiwen.com/subject/szgcmftx.html