392. Is Subsequence 难度:medium
来源:互联网 发布:最好的网络云盘 编辑:程序博客网 时间:2024/06/05 10:02
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
.
思路:
只要用两个指针来判断当前两个字符串中的字符是否相等即可。
程序:
class Solution {public: bool isSubsequence(string s, string t) { int s1 = s.size(); int t1 = t.size(); int i = 0; int j = 0; while(i < s1&&j < t1) { if(s[i] != t[j]) j++; else { i++; j++; } } return i == s1 ? true : false; }};
0 0
- 392. Is Subsequence 难度:medium
- LeetCode[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|week 9
- LeetCode392. Is Subsequence(Medium)
- 334. Increasing Triplet Subsequence 难度:medium
- LeetCode #392 - Is Subsequence - Medium
- 300. Longest Increasing Subsequence 类别:动态规划 难度:medium
- 376. Wiggle Subsequence 类别:动态规划 难度:medium
- (算法分析Week13)Is Subsequence[Medium]
- 167. Two Sum II - Input array is sorted 难度:medium
- 392.leetcode Is Subsequence (medium)[判断一个字符串是否是另一个字符串的子串]
- 77. Combinations 难度:medium
- 392. Is Subsequence
- 392.[LeetCode] Is Subsequence
- 【内核】进程切换 switch_to 与 __switch_to
- Android Data Binding实战-入门篇(补充)
- 洛谷 P1661 扩散
- CodeForces #367(706C)|动态规划
- torch学习笔记3.3:实现自定义模块(gpu)
- 392. Is Subsequence 难度:medium
- Javascript闭包(Closure)
- android 绘图基础 内含各种基本api
- scanf和printf的用法详解
- hdu1426
- Animator引用其中参数和状态的两种方法
- 递推--HDU 2501Tiling_easy version
- 高等数学公式
- git和github的关系