判断子序列

给定字符串 st ,判断 s 是否为 t 的子序列。

你可以认为 st 中仅包含英文小写字母。字符串 t 可能会很长(长度 ~= 500,000),而 s 是个短字符串(长度 <=100)。

字符串的一个子序列是原始字符串删除一些(也可以不删除)字符而不改变剩余字符相对位置形成的新字符串。(例如,"ace"是"abcde"的一个子序列,而"aec"不是)。

示例 1:
s = "abc", t = "ahbgdc"

返回 true.

示例 2:
s = "axc", t = "ahbgdc"

返回 false.

后续挑战
:

如果有大量输入的 S,称作S1, S2, ... , Sk 其中 k >= 10亿,你需要依次检查它们是否为 T 的子序列。在这种情况下,你会怎样改变代码?

 class Solution {
public boolean isSubsequence(String s, String t) {
int sindex = 0, tindex = 0;
while(sindex < s.length() && tindex < t.length()) {
if(s.charAt(sindex) == t.charAt(tindex)) {
sindex++;
}
tindex++;
}
if(sindex == s.length()) return true;
return false;
}
}

Leetcode 392.判断子序列的更多相关文章

  1. Java实现 LeetCode 392 判断子序列

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

  2. [LeetCode] 392. 判断子序列 ☆(动态规划)

    https://leetcode-cn.com/problems/is-subsequence/solution/java-dp-by-zxy0917-5/ 描述 给定字符串 s 和 t ,判断 s ...

  3. [Leetcode 392]判断子序列 Is Subsequence

    [思路] 判断s是否为t的子串,所以length(s)<=length(t).于是两个指针,一次循环. 将s.t转换为数组p1.p2. i为过程中s的匹配长度. i=0空串,单独讨论返回true ...

  4. Leetcode之动态规划(DP)专题-392. 判断子序列(Is Subsequence)

    Leetcode之动态规划(DP)专题-392. 判断子序列(Is Subsequence) 给定字符串 s 和 t ,判断 s 是否为 t 的子序列. 你可以认为 s 和 t 中仅包含英文小写字母. ...

  5. LeetCode 792. 匹配子序列的单词数(Number of Matching Subsequences)

    792. 匹配子序列的单词数 792. Number of Matching Subsequences 相似题目 392. 判断子序列

  6. [leetcode] 392. Is Subsequence (Medium)

    原题 判断子序列 /** * @param {string} s * @param {string} t * @return {boolean} */ var isSubsequence = func ...

  7. 392 Is Subsequence 判断子序列

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

  8. [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 ...

  9. [LeetCode 115] - 不同子序列(Distinct Subsequences)

    问题 给出字符串S和T,计算S中为T的不同的子序列的个数. 一个字符串的子序列是一个由该原始字符串通过删除一些字母(也可以不删)但是不改变剩下字母的相对顺序产生的一个新字符串.如,ACE是ABCDE的 ...

随机推荐

  1. 向fedora添加rpmfusion源

    http://blog.csdn.net/pu1030/article/details/7332036 有的rpmfusion地址有版本问题,找到一个比较好用的摘录一下: 从http://downlo ...

  2. JS基础1 — 代码要注意的一些问题

    1.在一对  <script></script>  标签中,有错的js代码,那么该错误代码后面的代码不会执行. 例子:<script> alert("He ...

  3. C# 语句 分支语句

    语句是指程序命令,按照顺序执行.可以分为   顺序语句  分支语句  循环语句 之前学习的内容都是按照顺序程序执行的,称之为顺序语句. 今天学的的内容是分支语句. 语句可以嵌套,可以是以分号结尾的单行 ...

  4. MFC U盘检测

    WM_DEVICECHANGE消息 查阅MSDN得知: The framework calls this member function to notify an application or dev ...

  5. 在Windows 10删除百度云盘的盘符

    1点击微软图标不放,然后点击R  打开运行命令 2输入  Regedit  进入注册表 3找到以下路径:HKEY_LOCAL_MACHINE  SOFTWARE  Microsoft  Windows ...

  6. Linux下文件以及文件名编码转换

    1.查看文件编码方式--file 文件名(但不是很准确) yang@mint-linux ~ $ file baidu.html baidu.html: HTML document, UTF-8 Un ...

  7. 解决android studio设置版本号

    获取版本号代码 /** * 获取版本号 * @return 当前应用的版本号 */ public static String getVersion(Context context) { try { P ...

  8. iOS perform action after period of inactivity (no user interaction)

    代码看完后感觉非常优秀 http://stackoverflow.com/questions/8085188/ios-perform-action-after-period-of-inactivity ...

  9. C++数据文件存储与加载(利用opencv)

    首先请先确认已经安装好了opencv3及以上版本. #include <opencv2/opencv.hpp>#include <iostream>#include <s ...

  10. lru缓存测试类

    package demo.mytest; import java.io.Serializable;import java.util.LinkedHashMap;import java.util.con ...