is-subsequence
public class Solution {
public boolean isSubsequence(String s, String t) {
int idx = 0;
for (int i=0; i<t.length()&&idx<s.length(); i++) {
if (s.charAt(idx) == t.charAt(i)) {
idx++;
}
}
return idx == s.length();
}
}
is-subsequence的更多相关文章
- [LeetCode] Arithmetic Slices II - Subsequence 算数切片之二 - 子序列
A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...
- [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 ...
- [LeetCode] Wiggle Subsequence 摆动子序列
A sequence of numbers is called a wiggle sequence if the differences between successive numbers stri ...
- [LeetCode] Increasing Triplet Subsequence 递增的三元子序列
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...
- [LeetCode] Longest Increasing Subsequence 最长递增子序列
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
- 【LeetCode】Increasing Triplet Subsequence(334)
1. Description Given an unsorted array return whether an increasing subsequence of length 3 exists o ...
- CF724D. Dense Subsequence[贪心 字典序!]
D. Dense Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- [tem]Longest Increasing Subsequence(LIS)
Longest Increasing Subsequence(LIS) 一个美丽的名字 非常经典的线性结构dp [朴素]:O(n^2) d(i)=max{0,d(j) :j<i&& ...
随机推荐
- Ionic入门五:表单
一.输入框 list 类同样可以用于 input 元素.item-input 和 item 类指定了文本框及其标签. 1.输入框属性:placeholder 以下实例中,默认为100%宽度(左右两侧没 ...
- POJ 2260 Error Correction 模拟 贪心 简单题
Error Correction Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6825 Accepted: 4289 ...
- 三、redis系列之事务
1. 绪言 Redis也提供了事务机制,可以一次执行多个命令,本质是一组命令的集合.一个事务中的所有命令都会序列化,按顺序地串行化执行而不会被其他命令插入,不许加塞.但Redis对事务的支持是部分支持 ...
- Eclipse 更改默认的编码 和 换行符
- 复习一下xml(c)
简单介绍 Using System.Xml; XMLDocument xml=new XmlDocument();xml.Load(path);//初始化一个实例 xml.Load(HttpConte ...
- 1020 Tree Traversals (25)(25 point(s))
problem Suppose that all the keys in a binary tree are distinct positive integers. Given the postord ...
- [ 转载 ] Java Jvm内存介绍
一.基础理论知识 1.java虚拟机的生命周期: Java虚拟机的生命周期 一个运行中的Java虚拟机有着一个清晰的任务:执行Java程序.程序开始执行时他才运行,程序结束时他就停止.你在同一台机器上 ...
- dataTransfer 对象
dataTransfer 对象 提供了对于预定义的剪贴板格式的访问,以便在拖曳操作中使用. DHTML元素属性列表 属性 描述 dropEffect 设置或获取拖曳操作的类型和要显示的光标类型. ef ...
- 排序算法之冒泡排序Java实现
排序算法之冒泡排序 舞蹈演示排序: 冒泡排序: http://t.cn/hrf58M 希尔排序:http://t.cn/hrosvb 选择排序:http://t.cn/hros6e 插入排序:ht ...
- hdu 3864 素数分解
题意:求n是否只有4个因子,如果是就输出除1外的所有因子. 模板题,就不排版了 #include<cstdio> #include<iostream> #include< ...