keep learning, keep coding!
Problem - Is Subsequence
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 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).
翻譯蒟蒻
給定兩個字串 s 和 t,如果 s 是 t 的子序列,則返回 true;否則返回 false。例如,”ace” 是 “abcde” 的子序列,而”aec”則不是。換句話說,如果字串 s 的所有字都按照相對順序出現在字串 t 中,即使其中有些字被刪除,仍然視為 s 是 t 的子序列。
Example 1:
1
2Input: s = "abc", t = "ahbgdc"
Output: trueExample 2:
1
2Input: s = "axc", t = "ahbgdc"
Output: false
Solution - JavaScript
1 | /** |
Solution - Ruby
1 | def is_subsequence(s, t) |
Solution - PHP
1 | function isSubsequence($s, $t) { |