mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 07:35:35 +08:00
Merge pull request #1452 from xiaofei-2020/exStr01
添加(0925.长按键入.md):增加typescript版本
This commit is contained in:
@ -209,6 +209,31 @@ var isLongPressedName = function(name, typed) {
|
||||
};
|
||||
```
|
||||
|
||||
### TypeScript
|
||||
|
||||
```typescript
|
||||
function isLongPressedName(name: string, typed: string): boolean {
|
||||
const nameLength: number = name.length,
|
||||
typeLength: number = typed.length;
|
||||
let i: number = 0,
|
||||
j: number = 0;
|
||||
while (i < nameLength && j < typeLength) {
|
||||
if (name[i] !== typed[j]) return false;
|
||||
i++;
|
||||
j++;
|
||||
if (i === nameLength || name[i] !== name[i - 1]) {
|
||||
// 跳过typed中的连续相同字符
|
||||
while (j < typeLength && typed[j] === typed[j - 1]) {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return i === nameLength && j === typeLength;
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
-----------------------
|
||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||
|
Reference in New Issue
Block a user