牛牛是一个热爱字符串的小牛,他最近对于字符串的子序列匹配问题产生了兴趣。给定两个仅包含小写英文字母的字符串s和t,你需要在字符串s的末尾添加最少的字符,使得字符串t成为字符串s的子序列。 子序列是由原字符串中删除一些字符(可以不删除)而不改变剩余字符相对位置形成的新字符串。 请返回添加到字符串s末尾的最少字符数,使得字符串t成为字符串s的子序列。
示例1
输入
"abc","a"
输出
0
示例2
输入
"nowcoder","nowcoing"
输出
3
备注:
1 字符串s和t仅包含小写英文字母
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param t string字符串 * @return int整型 */ public int minCharacters (String s, String t) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param t string字符串 * @return int整型 */ int minCharacters(string s, string t) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @param t string字符串 # @return int整型 # class Solution: def minCharacters(self , s , t ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param t string字符串 * @return int整型 */ public int minCharacters (string s, string t) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param t string字符串 * @return int整型 */ function minCharacters( s , t ) { // write code here } module.exports = { minCharacters : minCharacters };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @param t string字符串 # @return int整型 # class Solution: def minCharacters(self , s: str, t: str) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param t string字符串 * @return int整型 */ func minCharacters( s string , t string ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param t string字符串 * @return int整型 */ int minCharacters(char* s, char* t ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @param t string字符串 # @return int整型 # class Solution def minCharacters(s, t) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param t string字符串 * @return int整型 */ def minCharacters(s: String,t: String): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param t string字符串 * @return int整型 */ fun minCharacters(s: String,t: String): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param t string字符串 * @return int整型 */ public int minCharacters (String s, String t) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param t string字符串 * @return int整型 */ export function minCharacters(s: string, t: string): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param t string字符串 * @return int整型 */ func minCharacters ( _ s: String, _ t: String) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @param t string字符串 * @return int整型 */ pub fn minCharacters(&self, s: String, t: String) -> i32 { // write code here } }
"abc","a"
0
"nowcoder","nowcoing"
3