添加1047.删除字符串中的所有相邻重复项 Ruby实现
This commit is contained in:
parent
bf51d4730d
commit
7ae878753b
|
|
@ -475,6 +475,26 @@ impl Solution {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Ruby
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
def remove_duplicates(s)
|
||||||
|
#数组模拟栈
|
||||||
|
stack = []
|
||||||
|
s.each_char do |chr|
|
||||||
|
if stack.empty?
|
||||||
|
stack.push chr
|
||||||
|
else
|
||||||
|
head = stack.pop
|
||||||
|
#重新进栈
|
||||||
|
stack.push head, chr if head != chr
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return stack.join
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue