-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution2843.go
37 lines (33 loc) · 880 Bytes
/
solution2843.go
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
package solution2843
// ============================================================================
// 2843. Count Symmetric Integers
// URL: https://leetcode.com/problems/count-symmetric-integers/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/2843---Count-Symmetric-Integers
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_countSymmetricIntegers-24 4957764 223.8 ns/op 3 B/op 1 allocs/op
PASS
*/
import "strconv"
func countSymmetricIntegers(low int, high int) int {
ans := 0
for i := low; i <= high; i++ {
s := strconv.Itoa(i)
switch {
case len(s) == 2:
if s[0] == s[1] {
ans++
}
case len(s) == 4:
v1 := byte(s[0]) - '0' + s[1] - '0'
v2 := byte(s[2]) - '0' + s[3] - '0'
if v1 == v2 {
ans++
}
}
}
return ans
}