mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 16:36:41 +08:00
add: leetcode 0728 solution
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
package leetcode
|
||||
|
||||
func selfDividingNumbers(left int, right int) []int {
|
||||
var ans []int
|
||||
for num := left; num <= right; num++ {
|
||||
if selfDividingNum(num) {
|
||||
ans = append(ans, num)
|
||||
}
|
||||
}
|
||||
return ans
|
||||
}
|
||||
|
||||
func selfDividingNum(num int) bool {
|
||||
for d := num; d > 0; d = d / 10 {
|
||||
reminder := d % 10
|
||||
if reminder == 0 {
|
||||
return false
|
||||
}
|
||||
if num%reminder != 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user