mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Merge pull request #1051 from xiaofei-2020/stack5
添加(1047.删除字符串中的所有相邻重复项.md):增加typescript版本
This commit is contained in:
@ -267,8 +267,32 @@ var removeDuplicates = function(s) {
|
||||
};
|
||||
```
|
||||
|
||||
TypeScript:
|
||||
|
||||
```typescript
|
||||
function removeDuplicates(s: string): string {
|
||||
const helperStack: string[] = [];
|
||||
let i: number = 0;
|
||||
while (i < s.length) {
|
||||
let top: string = helperStack[helperStack.length - 1];
|
||||
if (top === s[i]) {
|
||||
helperStack.pop();
|
||||
} else {
|
||||
helperStack.push(s[i]);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
let res: string = '';
|
||||
while (helperStack.length > 0) {
|
||||
res = helperStack.pop() + res;
|
||||
}
|
||||
return res;
|
||||
};
|
||||
```
|
||||
|
||||
C:
|
||||
方法一:使用栈
|
||||
|
||||
```c
|
||||
char * removeDuplicates(char * s){
|
||||
//求出字符串长度
|
||||
|
Reference in New Issue
Block a user