-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution389.go
More file actions
44 lines (41 loc) · 890 Bytes
/
solution389.go
File metadata and controls
44 lines (41 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package solution389
// ============================================================================
// 389. Find the Difference
// URL: https://leetcode.com/problems/find-the-difference/
// ============================================================================
/*
goos: linux
goarch: amd64
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_findTheDifference-24 140786538 8.650 ns/op 0 B/op 0 allocs/op
PASS
*/
func findTheDifference(s string, t string) byte {
if len(s) == 0 {
return t[0]
}
n := 0
sl := make([]int, 26)
for i := 0; i < len(t); i++ {
n = int(t[i]) - 97
if sl[n] == 0 {
sl[n] = 1
} else {
sl[n] = 0
}
}
for i := 0; i < len(s); i++ {
n = int(s[i]) - 97
if sl[n] == 0 {
sl[n] = 1
} else {
sl[n] = 0
}
}
for i := 0; i < len(t); i++ {
if sl[i] == 1 {
return byte(i + 97)
}
}
return 'a'
}