Skip to content

Commit 2ca5f40

Browse files
authored
feat: add golang solutions to lc problem: No.0389 (doocs#885)
1 parent f67f0ef commit 2ca5f40

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

solution/0300-0399/0389.Find the Difference/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,24 @@ char findTheDifference(char *s, char *t) {
192192
}
193193
```
194194

195+
### **Go**
196+
197+
```go
198+
func findTheDifference(s, t string) byte {
199+
cnt := [26]int{}
200+
for _, ch := range s {
201+
cnt[ch-'a']++
202+
}
203+
for i := 0; ; i++ {
204+
ch := t[i]
205+
cnt[ch-'a']--
206+
if cnt[ch-'a'] < 0 {
207+
return ch
208+
}
209+
}
210+
}
211+
```
212+
195213
### **...**
196214

197215
```

solution/0300-0399/0389.Find the Difference/README_EN.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,24 @@ char findTheDifference(char *s, char *t) {
168168
}
169169
```
170170

171+
### **Go**
172+
173+
```go
174+
func findTheDifference(s, t string) byte {
175+
cnt := [26]int{}
176+
for _, ch := range s {
177+
cnt[ch-'a']++
178+
}
179+
for i := 0; ; i++ {
180+
ch := t[i]
181+
cnt[ch-'a']--
182+
if cnt[ch-'a'] < 0 {
183+
return ch
184+
}
185+
}
186+
}
187+
```
188+
171189
### **...**
172190

173191
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
func findTheDifference(s, t string) byte {
2+
cnt := [26]int{}
3+
for _, ch := range s {
4+
cnt[ch-'a']++
5+
}
6+
for i := 0; ; i++ {
7+
ch := t[i]
8+
cnt[ch-'a']--
9+
if cnt[ch-'a'] < 0 {
10+
return ch
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)