392. Is Subsequence LeetCode
来源:互联网 发布:微贷网高收益网络理财 编辑:程序博客网 时间:2024/06/06 09:29
Given a string s and a string t, check if s is subsequence of t.
You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string, and s is a short string (<=100).
A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ace"
is a subsequence of "abcde"
while "aec"
is not).
Example 1:
s = "abc"
, t = "ahbgdc"
Return true
.
Example 2:
s = "axc"
, t = "ahbgdc"
Return false
.
题目解析:改题目就是要求在给定的字符串中找到其“子字符串”,这里的子字符串并不是传统的形式,而是只在乎顺序而不在乎其字符串中字符的连贯。这就比较简单了,只需要一一检查子字符串在给定字符串中是否存在即可。
代码:
class Solution {public: bool isSubsequence(string s, string t) { int m=t.size(); int k=0; //用于遍历字符串s for(int i=0;i<m;i++) //循环检查给定字符串 { if(s[k]==t[i]) { k++; } } if(k==s.size()) return true;//判断子字符串是否正确存在与给定字符串的条件 else return false; }};
0 0
- 392.[LeetCode] Is Subsequence
- LeetCode 392. Is Subsequence
- [LeetCode] 392. Is Subsequence
- 【leetcode】392. Is Subsequence
- 【LeetCode】392. Is Subsequence
- 【LeetCode】392. Is Subsequence
- Leetcode 392. Is Subsequence
- leetcode 392. Is Subsequence
- LeetCode 392. Is Subsequence
- 【LeetCode】 392. Is Subsequence
- LeetCode 392. Is Subsequence
- LeetCode 392. Is Subsequence
- Leetcode-392. Is Subsequence
- Leetcode-392. Is Subsequence
- Leetcode 392. Is Subsequence
- leetcode 392. Is Subsequence
- 【LeetCode】392. Is Subsequence
- 392. Is Subsequence LeetCode
- servlet连接MySQL
- java集合工具类,并发集合类,阻塞容器类接口
- BZOJ2698: 染色
- 使用AndroidStudio中的CMake开发JNI
- 图片隐写术总结
- 392. Is Subsequence LeetCode
- Android Activity的生命周期
- 在linux中安装sonar
- Java类的加载、连接和初始化
- [BZOJ3211]花神游历各国 势能线段树
- mysql_fetch_row,mysql_fetch_array,mysql_fetch_assoc的区别
- Linux调优资料
- ARM汇编基础
- mysql数据备份及还原