392. Is Subsequence Medium
来源:互联网 发布:sql delete语句 编辑:程序博客网 时间:2024/06/11 10:35
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
.
思路:判断条件是s中字符都在t中并且顺序和在t中顺序一样。直接循环查找,用count记录s中有多少顺序相同字符在t中,count = s.size()返回true。
class Solution {public: bool isSubsequence(string s, string t) { bool sub = false; int count = 0; for (int i = 0, j = 0; i < s.size(), j < t.size(); j++) { if (s[i] == t[j]) { count++; i++; } } if (count == s.size()) { sub = true; } return sub; }};
阅读全文
0 0
- 392. Is Subsequence -Medium
- 392. Is Subsequence Medium
- 392. Is Subsequence 难度:medium
- Leetcode 392. Is Subsequence (Medium) (cpp)
- LeetCode解题报告 392. Is Subsequence [medium]
- LeetCode[392. Is Subsequence] 难度[medium]
- [leetcode 392. Is Subsequence]medium|week 9
- LeetCode392. Is Subsequence(Medium)
- LeetCode #392 - Is Subsequence - Medium
- (算法分析Week13)Is Subsequence[Medium]
- 392.leetcode Is Subsequence (medium)[判断一个字符串是否是另一个字符串的子串]
- 392. Is Subsequence
- 392.[LeetCode] Is Subsequence
- 392. Is Subsequence
- 392. Is Subsequence
- LeetCode 392. Is Subsequence
- 392. Is Subsequence
- 392. Is Subsequence
- 1005. Spell It Right (20)
- 23. Merge k Sorted Lists&优先队列
- 因特网、万维网和互联网
- Spring Boot单元测试
- java.lang.IllegalStateException: No output folder
- 392. Is Subsequence Medium
- Business Center
- android audio/linux alsa音频-应用与驱动的接口
- P3628 [APIO2010]特别行动队
- 学生点名系统
- 第七章 假设检验(2)
- 【一头扎进JMS】(3)----ActiviteMQ点对点消息实现+消息监听
- 【C++】【LeetCode】35. Search Insert Position
- 求解数组中任意两个元素的和最接近某一个数