Leetcode Note: Go - Convert Integer to the Sum of Two No Zero Integers
Convert Integer to the Sum of Two No-Zero Integers - LeetCode
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/
- Go 言語で取り組んだメモ
回答
Golang solution faster than 100% - Convert Integer to the Sum of Two No-Zero Integers - LeetCode
https://leetcode.com/problems/convert-integer-to-the-sum-of-two-no-zero-integers/solutions/1052276/golang-solution-faster-than-100/
func getNoZeroIntegers(n int) []int {
for i := 1; i < n; i++ {
containsZero := false
a := i
b := n - i
for a > 0 { // the first number has no zeros
if a%10 == 0 {
containsZero = true
break
}
a /= 10
}
if !containsZero {
for b > 0 { // second number has no zeros
if b%10 == 0 {
containsZero = true
break
}
b /= 10
}
}
if !containsZero { // if none of the numbers have zeros then return
return []int{i, n - i}
}
}
return []int{}
}