-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution728.go
More file actions
40 lines (32 loc) · 871 Bytes
/
solution728.go
File metadata and controls
40 lines (32 loc) · 871 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
package solution728
import "strconv"
// ============================================================================
// 728. Self Dividing Numbers
// URL: https://leetcode.com/problems/self-dividing-numbers/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/728
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_selfDividingNumbers
Benchmark_selfDividingNumbers-24 7992819 149.7 ns/op 248 B/op 5 allocs/op
PASS
*/
func selfDividingNumbers(left int, right int) []int {
var numbers []int
outer:
for i := left; i <= right; i++ {
s := strconv.Itoa(i)
for j := 0; j < len(s); j++ {
switch {
case s[j] == '0':
continue outer
case i%int(s[j]-'0') != 0:
continue outer
}
}
numbers = append(numbers, i)
}
return numbers
}