LeetCode 925 長按鍵入

2022-06-10 07:39:06 字數 978 閱讀 7443

你的朋友正在使用鍵盤輸入他的名字name。偶爾,在鍵入字元c時,按鍵可能會被長按,而字元可能被輸入 1 次或多次。

你將會檢查鍵盤輸入的字元typed。如果它對應的可能是你的朋友的名字(其中一些字元可能被長按),那麼就返回true

示例1:

輸入:name = "alex", typed = "aaleex"

輸出:true

解釋:'alex' 中的 'a' 和 'e' 被長按。

示例2:

輸入:name = "saeed", typed = "ssaaedd"

輸出:false

解釋:'e' 一定需要被鍵入兩次,但在 typed 的輸出中不是這樣。

示例3:

輸入:name = "leelee", typed = "lleeelee"

輸出:true

示例4:

輸入:name = "laiden", typed = "laiden"

輸出:true

解釋:長按名字中的字元並不是必要的。

name.length <= 1000

typed.length <= 1000

name 和 typed 的字元都是小寫字母。

class solution 

else if(j > 0 && typed[j] == typed[j - 1])

else

}return i == name.length();

}};

LeetCode925 長按鍵入

你的朋友正在使用鍵盤輸入他的名字 name。偶爾,在鍵入字元 c 時,按鍵可能會被長按,而字元可能被輸入 1 次或多次。你將會檢查鍵盤輸入的字元 typed。如果它對應的可能是你的朋友的名字 其中一些字元可能被長按 那麼就返回 true。示例 1 輸入 name alex typed aaleex ...

LeetCode 925 長按鍵入

你的朋友正在使用鍵盤輸入他的名字 name。偶爾,在鍵入字元 c 時,按鍵可能會被長按,而字元可能被輸入 1 次或多次。你將會檢查鍵盤輸入的字元 typed。如果它對應的可能是你的朋友的名字 其中一些字元可能被長按 那麼就返回 true。示例 1 輸入 name alex typed aaleex ...

LeetCode 925 長按鍵入

你的朋友正在使用鍵盤輸入他的名字 name。偶爾,在鍵入字元 c 時,按鍵可能會被長按,而字元可能被輸入 1 次或多次。你將會檢查鍵盤輸入的字元 typed。如果它對應的可能是你的朋友的名字 其中一些字元可能被長按 那麼就返回 true。示例 1 輸入 name alex typed aaleex ...