欢迎光临散文网 会员登陆 & 注册

Leetcode 2486. Append Characters to String to Make Subsequence

2022-11-27 13:10 作者:您是打尖儿还是住店呢  | 我要投稿


Medium

30Add to ListShare

You are given two strings s and t consisting of only lowercase English letters.

Return the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s.

A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.

 

Example 1:

Input: s = "coaching", t = "coding"Output: 4Explanation: Append the characters "ding" to the end of s so that s = "coachingding". Now, t is a subsequence of s ("coachingding"). It can be shown that appending any 3 characters to the end of s will never make t a subsequence.

Example 2:

Input: s = "abcde", t = "a"Output: 0Explanation: t is already a subsequence of s ("abcde").

Example 3:

Input: s = "z", t = "abcde"Output: 5Explanation: Append the characters "abcde" to the end of s so that s = "zabcde". Now, t is a subsequence of s ("zabcde"). It can be shown that appending any 4 characters to the end of s will never make t a subsequence.


感觉这道题可以判断为easy的,其实就是判断一下,按照字符串的顺序,相同的一共有多少个字符,判断出来后,剩下就是字符串长度减去相同的字符数量即可;



Runtime: 5 ms, faster than 80.00% of Java online submissions for Append Characters to String to Make Subsequence.

Memory Usage: 43.3 MB, less than 80.00% of Java online submissions for Append Characters to String to Make Subsequence.



Leetcode 2486. Append Characters to String to Make Subsequence的评论 (共 条)

分享到微博请遵守国家法律