-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution3019.go
More file actions
45 lines (41 loc) · 955 Bytes
/
Copy pathsolution3019.go
File metadata and controls
45 lines (41 loc) · 955 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
45
package solution3019
// ============================================================================
// 3019. Number of Changing Keys
// URL: https://leetcode.com/problems/number-of-changing-keys/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/3019---Number-of-Changing-Keys
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_countKeyChanges-24 373075306 3.215 ns/op 0 B/op 0 allocs/op
PASS
*/
func countKeyChanges(s string) int {
changes := 0
for i := 0; i < len(s)-1; i++ {
a := i
b := i + 1
ch1 := s[a]
ch2 := s[b]
switch {
case ch1 == ch2:
continue
case ch1+32 == ch2+32:
continue
case ch1-32 == ch2-32:
continue
case ch1-32 == ch2:
continue
case ch1 == ch2-32:
continue
case ch1+32 == ch2:
continue
case ch1 == ch2+32:
continue
default:
changes++
}
}
return changes
}