动态规划——392. Is Subsequence
来源:互联网 发布:刘欢和李宗盛 知乎 编辑:程序博客网 时间:2024/06/08 05:18
题目描述
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
.
解题思路
下标i、j表示s和t的当前字母,s[i]==t[j]时i++;
最后判断i是否等于s.size()
代码如下
class Solution {public: bool isSubsequence(string s, string t) { int i = 0, j = 0;if (s.empty())return true;while (j < t.size()) {if (s[i] == t[j]) {i++;j++;}elsej++;}return i == s.size(); }};
题目简单,可是连一个状态转移方程都没有,很不像动态规划,但是,想了许久还没想到其他方法(以后想到再来更新)
- 动态规划——392. Is Subsequence
- 动态规划-392. Is Subsequence
- LeetCode—392. Is Subsequence
- leetcode之392. Is Subsequence(C++解法 动态规划 贪心 模式匹配)
- 动态规划—杭电1159 Common Subsequence
- 动态规划 Common Subsequence
- leetcode——Is Subsequence
- 【动态规划】poj1458 common subsequence
- POJ1458 Common Subsequence 动态规划
- ZOJ 3123 Subsequence (动态规划)
- 动态规划【Longest Ordered Subsequence】
- UVA11404 - Palindromic Subsequence - 动态规划
- Hdu1159 - Common Subsequence - 动态规划
- HDU1159 Common Subsequence(动态规划)
- 动态规划 Longest Ordered Subsequence
- Common Subsequence 动态规划I
- poj1458 Common Subsequence 动态规划
- HDU_1159 Common Subsequence 【动态规划】
- 一次真实项目性能测试与调优的总结
- webpack-dev-server无法自动编译热更新
- 基础算法题-正则相关
- HEX文件和BIN文件格式的区别
- Python网络爬虫(Get、Post抓取方式)
- 动态规划——392. Is Subsequence
- mysql数据库my.ini文件内容
- Array/数组类型的转换方法——toLocaleString()
- 高性能mysql(三)选择优化的数据类型
- 移动端的三种适配
- 文章标题
- 跨站请求伪造(CSRF)
- Spring 延迟初始化
- Unity中Editor的ProgressBar的使用demo