TreeviewCopyright © aleen42 all right reserved, powered by aleen42
925. 长按键入
https://leetcode-cn.com/problems/long-pressed-name/
Java
class Solution {
public boolean isLongPressedName(String name, String typed) {
char[] nameChars = name.toCharArray();
int index = 0;
for(char t : typed.toCharArray()) {
if(index < nameChars.length && t == nameChars[index]) index++;
else if(index == 0 || t != nameChars[index - 1]) return false;
}
return index == name.length();
}
}
Python
'''
Author: Goog Tech
Date: 2020-08-30 20:00:20
LastEditTime: 2020-08-30 20:01:52
Description: https://leetcode-cn.com/problems/long-pressed-name/
FilePath: \leetcode-googtech\#925. Long Pressed Name\Solution.py
WebSite: https://algorithm.show/
'''
class Solution(object):
def isLongPressedName(self, name, typed):
"""
:type name: str
:type typed: str
:rtype: bool
"""
''' 待解. . . '''