Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7ae8787

Browse files
添加1047.删除字符串中的所有相邻重复项 Ruby实现
1 parent bf51d47 commit 7ae8787

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎problems/1047.删除字符串中的所有相邻重复项.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,26 @@ impl Solution {
475475
}
476476
```
477477

478+
### Ruby
479+
480+
```ruby
481+
def remove_duplicates(s)
482+
#数组模拟栈
483+
stack = []
484+
s.each_char do |chr|
485+
if stack.empty?
486+
stack.push chr
487+
else
488+
head = stack.pop
489+
#重新进栈
490+
stack.push head, chr if head != chr
491+
end
492+
end
493+
494+
return stack.join
495+
end
496+
```
497+
478498
<p align="center">
479499
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
480500
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /