diff --git a/leetcode/392. Is Subsequence/README.md b/leetcode/392. Is Subsequence/README.md index 563c12fa..26c70b4e 100644 --- a/leetcode/392. Is Subsequence/README.md +++ b/leetcode/392. Is Subsequence/README.md @@ -1,14 +1,8 @@ # [392. Is Subsequence (Easy)](https://leetcode.com/problems/is-subsequence/) -

Given a string s and a string t, check if s is subsequence of t.

+

Given two strings s and t, return true if s is a subsequence of t, or false otherwise.

-

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).

- -

Follow up:
-If there are lots of incoming S, say S1, S2, ... , Sk where k >= 1B, and you want to check one by one to see if T has its subsequence. In this scenario, how would you change your code?

- -

Credits:
-Special thanks to @pbrother for adding this problem and creating all test cases.

+

A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not).

 

Example 1:

@@ -23,19 +17,24 @@ Special thanks to @pbrother for add +

 

+Follow up: Suppose there are lots of incoming s, say s1, s2, ..., sk where k >= 109, and you want to check one by one to see if t has its subsequence. In this scenario, how would you change your code? + +**Companies**: +[Adobe](https://leetcode.com/company/adobe), [Amazon](https://leetcode.com/company/amazon), [Google](https://leetcode.com/company/google) **Related Topics**: -[Binary Search](https://leetcode.com/tag/binary-search/), [Dynamic Programming](https://leetcode.com/tag/dynamic-programming/), [Greedy](https://leetcode.com/tag/greedy/) +[Two Pointers](https://leetcode.com/tag/two-pointers/), [String](https://leetcode.com/tag/string/), [Dynamic Programming](https://leetcode.com/tag/dynamic-programming/) **Similar Questions**: * [Number of Matching Subsequences (Medium)](https://leetcode.com/problems/number-of-matching-subsequences/) * [Shortest Way to Form String (Medium)](https://leetcode.com/problems/shortest-way-to-form-string/) -## Solution 1. +## Solution 1. Two Pointers ```cpp // OJ: https://leetcode.com/problems/is-subsequence/ diff --git a/leetcode/392. Is Subsequence/s1.cpp b/leetcode/392. Is Subsequence/s1.cpp deleted file mode 100644 index 2a4d7949..00000000 --- a/leetcode/392. Is Subsequence/s1.cpp +++ /dev/null @@ -1,14 +0,0 @@ -// OJ: https://leetcode.com/problems/is-subsequence/ -// Author: github.com/lzl124631x -// Time: O(M + N) -// Space: O(1) -class Solution { -public: - bool isSubsequence(string s, string t) { - int i = 0, j = 0, M = s.size(), N = t.size(); - for (; i < M && j < N; ++j) { - if (s[i] == t[j]) ++i; - } - return i == M; - } -}; \ No newline at end of file