There are 3 possible approaches: DP, divide&conquer and greedy. And apparently, DP has O(n^2) complexity (TLE), DivideConquer can only be worse. Greedy can be O(n)! And its code is amazingly brief:

class Solution {
public:
bool isSubsequence(string s, string t) {
size_t lens = s.length();
size_t lent = t.length(); int is = , it = ;
while(is < lens && it < lent)
{
char cs = s[is], ct = t[it];
if(cs != ct) it ++;
else is++, it++;
} return is == lens;
}
};

LeetCode "Is Subsequence"的更多相关文章

  1. [LeetCode] 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] Wiggle Subsequence 摆动子序列

    A sequence of numbers is called a wiggle sequence if the differences between successive numbers stri ...

  3. LeetCode "Wiggle Subsequence" !

    Another interesting DP. Lesson learnt: how you define state is crucial.. 1. if DP[i] is defined as, ...

  4. [LeetCode] Is Subsequence 题解

    前言 这道题的实现方法有很多,包括dp,贪心算法,二分搜索,普通实现等等. 题目 Given a string s and a string t, check if s is subsequence ...

  5. LeetCode——Is Subsequence

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

  6. leetcode 376Wiggle Subsequence

    用dp解 1)up定义为nums[i-1] < nums[i] down nums[i-1] > nums[i] 两个dp数组, up[i],记录包含nums[i]且nums[i-1] & ...

  7. [LeetCode] Arithmetic Slices II - Subsequence 算数切片之二 - 子序列

    A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...

  8. [LeetCode] Increasing Triplet Subsequence 递增的三元子序列

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  9. [LeetCode] Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

随机推荐

  1. BSTR 的奥秘

    初学COM,总觉得BSTR很神秘,对于这种新的数据类型,总有很多疑问,那么BSTR到底是什么类型呢? 我们可以在头文件中的定义中最终找到 wchar这个类型被定义为BSTR,那么BSTR是wchar吗 ...

  2. schematool -dbType mysql -initSchema hive startup failed...try this

    schematool -dbType mysql -initSchema hive startup failed

  3. 深入理解JavaScript系列:史上最清晰的JavaScript的原型讲解

    一说起JavaScript就要谈的几个问题,原型就是其中的一个.说了句大话,史上最清晰.本来是想按照大纲式的行文写一下,但写到后边感觉其实就一个概念,没有什么条理性,所以下面就简单按照概念解释的模式谈 ...

  4. Maven指令

    mvn clean compile  //clean告诉Maven清理输出目录target/,compile告诉Maven编译项目主代码. mvn clean test  //清理输出目录target ...

  5. Jmeter增加压力机方法

    windows: 需要别人的机器也安装jmeter 在别人的机器上运行jmeter-server.bat 修改jmeter.properties文件,查找remote_hosts 原始:remote_ ...

  6. LPTHW 结束了

    基本上在学习了LPTHW的 类 继承 和 合成以后基本就结束. 后面几章都是根据web.py进行网页编程,以及自动化测试的.目前来看不太感兴趣. 稍后我可能找个实际项目进行锻炼下,比如 Crossin ...

  7. background-position

    在学习网页"换肤"效果时:对background-position的理解更深了. 这是我使用的一整张图片:

  8. cocos多点触控实效注意事项

    一定要设置AppController.mm的 [eaglView setMultipleTouchEnabled:YES];

  9. SEO如何辨别真假Baiduspider

    我们站长查看网站访问数据,分析IP来源是我们站长的日常工作,对一些异常的IP段,我们首先要区分是否是搜索引擎蜘蛛的IP段,以免误伤,下面我们就以2段IP为例,一个是百度蜘蛛的220.181.108.1 ...

  10. 记录一个UDP收包丢包的问题

    这几天写GB28181平台接入层代码,对收到的PS包进行解包时,总是出现误码,最终导致rtsp点播服务中画面花屏. 分析了码流抓包数据之后,发现网络上没有丢包,遂认为PS流解包代码有bug,于是埋头分 ...