原题

判断子序列

/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
var isSubsequence = function(s, t) {
var sl = s.length;
var tl = t.length;
if (sl === 0) {
return true;
}
if (tl < sl) {
return false;
}
var sindex = 0;
for (let i = 0; i < tl; i++) {
if (s[sindex] == t[i]) {
sindex++;
} if (sindex === sl) {
return true;
}
}
return false;
};

[leetcode] 392. Is Subsequence (Medium)的更多相关文章

  1. LeetCode 392. Is Subsequence

    Given a string s and a string t, check if s is subsequence of t. You may assume that there is only l ...

  2. [leetcode]392. Is Subsequence 验证子序列

    Given a string s and a string t, check if s is subsequence of t. You may assume that there is only l ...

  3. LeetCode 392. Is Subsequence 详解

    题目详情 给定字符串 s 和 t ,判断 s 是否为 t 的子序列. 你可以认为 s 和 t 中仅包含英文小写字母.字符串 t 可能会很长(长度 ~= 500,000),而 s 是个短字符串(长度 & ...

  4. 【LeetCode】392. Is Subsequence 解题报告(Python)

    [LeetCode]392. Is Subsequence 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/is-subseq ...

  5. 392. Is Subsequence

    392. Is Subsequence 水题,先是判断长度,长度t比s小,返回false,然后从左到右扫描t,然后同时扫描s,如果相同,s的index就往后拉一个,如果s的index等于s长度,返回t ...

  6. [array] leetcode - 48. Rotate Image - Medium

    leetcode - 48. Rotate Image - Medium descrition You are given an n x n 2D matrix representing an ima ...

  7. [array] leetcode - 39. Combination Sum - Medium

    leetcode - 39. Combination Sum - Medium descrition Given a set of candidate numbers (C) (without dup ...

  8. [array] leetcode - 31. Next Permutation - Medium

    leetcode - 31. Next Permutation - Medium descrition Implement next permutation, which rearranges num ...

  9. [leetcode] 300. Longest Increasing Subsequence (Medium)

    题意: 求最长增长的子序列的长度. 思路: 利用DP存取以i作为最大点的子序列长度. Runtime: 20 ms, faster than 35.21% of C++ online submissi ...

随机推荐

  1. coci2018 题解

    plahte 给定一些矩形和一些有颜色的点,求每个矩形上有多少种颜色的点,保证矩形只有包含和不相交两种关系,规模 \(10^5\). 把每个矩形看成一个点,用扫描线建出森林,同时也顺便处理点. 然后做 ...

  2. 使用AnimateWindow来实现窗口淡入淡出(主要有四种动画,滚动,滑动,折叠或展开,和淡入淡出)

    如果是在VC6下进行编译,应引入下面的预编译宏,注意放在windows.h的前面#undef  WINVER   #define  WINVER   0x500为什么要引入上面的宏呢?看看winuse ...

  3. STL函数static void (* set_malloc_handler(void (*f)()))()与函数指针解析

    在C++ STL的SGI实现版本中,一级空间配置器class __malloc_alloc_template中有一个静态函数的实现如下: static void (*set_malloc_handle ...

  4. PHP调用语音合成接口

    百度TTS 语音合成 //百度文件转换成语音 private function toSpeech($text) { define('DEMO_CURL_VERBOSE', false); $obj=[ ...

  5. java-mysql(2) Prepared statement

    上一篇学习了java如何链接配置mysql,这篇学习下java如何处理sql预处理语句(PreparedStatement),首先是一个sql预处理的例子: package core; import ...

  6. 利用GitLab自动同步软件仓库

    利用GitLab自动同步GitHub.Gitee.Bitbucket软件仓库 我在码云的账号:userName密码:password项目地址:https://gitee.com/Bytom/bytom ...

  7. Nio编程模型总结

    终于,这两天的考试熬过去了, 兴致冲冲的来整理笔记来, 这篇博客是我近几天的NIO印象笔记汇总,记录了对Selector及Selector的重要参数的理解,对Channel的理解,常见的Channel ...

  8. kubernetes实战篇之windows添加自签ca证书信任

    系列目录 由于服务端设置了https访问,因此如果通过浏览器访问时会提示证书不被信任,但是仍然可以通过处理继续访问.但是在自动化环境中,都是通过命令来请求的,这样不受信任的https就会报错误,这样我 ...

  9. maven的下载与安装,卸载替换eclipse自带的maven

    首先呢,博主在这里给大家一个建议,最好不要用eclipse自带的maven.因为这家伙总会出现一些这样那样的错误,比如常见的jar包下载不全或者是install打包报错等等. 博主用了一段时间,还是觉 ...

  10. Confluence5.6.6安装和破解

    1.安装confluence 1. 软件环境说明 # 安装 jdk [root@wiki_5-- jar]# cat /etc/redhat-release CentOS Linux release ...