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. business knowledge

    Finance knowledge Trading---At the core of our business model is Trading, which involves the buying ...

  2. Maven构件解析(转)

    文章转自http://gavinwind2000.iteye.com/blog/2290652 谢谢博主的总结! 在Maven中,任何一个依赖.插件或者项目构建的输出,都可以称之为构件. Maven在 ...

  3. UVA 12549 - 二分图匹配

    题意:给定一个Y行X列的网格,网格种有重要位置和障碍物.要求用最少的机器人看守所有重要的位置,每个机器人放在一个格子里,面朝上下左右四个方向之一发出激光直到射到障碍物为止,沿途都是看守范围.机器人不会 ...

  4. softwareTesting_work1

    1.12306手机APP软件测评 首先是软件界面,iPhone版本和android版本长得是一模一样,虽然是注重功能的软件,但是一样样的界面让人完全感受不到软件设计者的诚意啊. 还有就是软件图片和图标 ...

  5. Stars_树状数组

    Problem Description Astronomers often examine star maps where stars are represented by points on a p ...

  6. charles使用

    charles和fillder功能差不多,易用性更好些 1.安装和破解,替换charles.jar文件 2.手机代理: 设置charles 设置手机wifi将http代理修改成手动,填写本机ip地址和 ...

  7. js活动倒计时

    html代码: <div "></div> <div "></div> <div "></div> ...

  8. CLR via C# 3rd - 02 - Building, Packaging, Deploying, and Administering Applications and Types

    1. C# Compiler - CSC.exe            csc.exe /out:Program.exe /t:exe /r:MSCorLib.dll Program.cs       ...

  9. [读书笔记]java中的volatile关键词

    以下内容大多来自周志明的<深入理解Java虚拟机>. 当一个变量被volatile修饰后,它将具备两种特性: 1. 保证此变量对所有线程的可见性,这里的“可见性”是指当一条线程修改了这个变 ...

  10. java压缩和解压字符串,Byte数组,String

    在网上找到的压缩解压的工具类,可以压缩String字符串 /*** * 压缩GZip * * @param data * @return */ public static byte[] gZip(by ...