LeetCode 392. Is Subsequence

来源:互联网 发布:js实现word预览 编辑:程序博客网 时间:2024/05/17 04:13
public class Solution {    public boolean isSubsequence(String s, String t) {        int ls = s.length();        int lt = t.length();        if (ls > lt) return false;        int iS = 0;        int iT = 0;        while (iS < ls) {        if (iT == lt || ls - iS > lt - iT) return false;        if (s.charAt(iS) == t.charAt(iT)) {        iS++;        iT++;        } else iT++;        }        return true;    }}

0 0
原创粉丝点击