diff --git a/problems/0100.相同的树.md b/problems/0100.相同的树.md index e4eb412a..df0a5dd1 100644 --- a/problems/0100.相同的树.md +++ b/problems/0100.相同的树.md @@ -159,7 +159,7 @@ public: return false; } que.push(leftNode->left); // 添加p节点的左子树节点 - que.push(rightNode->left); // 添加q节点的左子树节点点 + que.push(rightNode->left); // 添加q节点的左子树节点 que.push(leftNode->right); // 添加p节点的右子树节点 que.push(rightNode->right); // 添加q节点的右子树节点 } diff --git a/problems/0925.长按键入.md b/problems/0925.长按键入.md index ef712252..c851a8df 100644 --- a/problems/0925.长按键入.md +++ b/problems/0925.长按键入.md @@ -9,6 +9,7 @@ # 925.长按键入 题目链接:https://leetcode-cn.com/problems/long-pressed-name/ + 你的朋友正在使用键盘输入他的名字 name。偶尔,在键入字符 c 时,按键可能会被长按,而字符可能被输入 1 次或多次。 你将会检查键盘输入的字符 typed。如果它对应的可能是你的朋友的名字(其中一些字符可能被长按),那么就返回 True。 @@ -98,7 +99,36 @@ public: # 其他语言版本 Java: - +```java +class Solution { + public boolean isLongPressedName(String name, String typed) { + int i = 0, j = 0; + int m = name.length(), n = typed.length(); + while (i< m && j < n) { + if (name.charAt(i) == typed.charAt(j)) { // 相同则同时向后匹配 + i++; j++; + } + else { + if (j == 0) return false; // 如果是第一位就不相同直接返回false + // 判断边界为n-1,若为n会越界,例如name:"kikcxmvzi" typed:"kiikcxxmmvvzzz" + while (j < n-1 && typed.charAt(j) == typed.charAt(j-1)) j++; + if (name.charAt(i) == typed.charAt(j)) { // j跨越重复项之后再次和name[i]匹配 + i++; j++; // 相同则同时向后匹配 + } + else return false; + } + } + // 说明name没有匹配完 + if (i < m) return false; + // 说明type没有匹配完 + while (j < n) { + if (typed.charAt(j) == typed.charAt(j-1)) j++; + else return false; + } + return true; + } +} +``` Python: ```python class Solution: diff --git a/problems/1002.查找常用字符.md b/problems/1002.查找常用字符.md index 82dbf4cf..723e5656 100644 --- a/problems/1002.查找常用字符.md +++ b/problems/1002.查找常用字符.md @@ -169,6 +169,7 @@ class Solution { } } ``` +Python ```python class Solution: def commonChars(self, words: List[str]) -> List[str]: