Skip to content

Commit a50e40f

Browse files
committed
feat: 1047
1 parent 3a64bb5 commit a50e40f

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# [1047. Remove All Adjacent Duplicates In String](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/)
2+
3+
## 2019/08/31
4+
5+
### 题目 💗[easy]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package removeDuplicates
2+
3+
func removeDuplicates(S string) string {
4+
isDiff := true
5+
for isDiff {
6+
isDiff = false
7+
for i := 0; i < len(S)-1; i++ {
8+
if S[i] == S[i+1] {
9+
S = S[:i] + S[i+2:] // 去掉i 和 i+1
10+
i--
11+
isDiff = true
12+
}
13+
}
14+
15+
}
16+
return S
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package removeDuplicates
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
var tcs = []struct {
10+
N1 string
11+
ans string
12+
}{
13+
{
14+
"abbaca",
15+
"ca",
16+
},
17+
}
18+
19+
func Test_bitwiseComplement(t *testing.T) {
20+
ast := assert.New(t)
21+
for _, tc := range tcs {
22+
ast.Equal(tc.ans, removeDuplicates(tc.N1), "输入:%v", tc)
23+
}
24+
}

0 commit comments

Comments
 (0)