Leetcode Note: Go - Find the K Beauty of a Number

Find the K-Beauty of a Number - LeetCode
https://leetcode.com/problems/find-the-k-beauty-of-a-number/

  • Go 言語で取り組んだメモ

回答

Go / GoLang | Time: O(n) / 0 ms / 100% | Space: O(n) / 2 MB / 100% - Find the K-Beauty of a Number - LeetCode
https://leetcode.com/problems/find-the-k-beauty-of-a-number/solutions/2038913/go-golang-time-o-n-0-ms-100-space-o-n-2-mb-100/

func divisorSubstrings(num int, k int) int {
    result, s := 0, strconv.Itoa(num)
    
    for i := k - 1; i < len(s); i++ {
        sub := s[i - k + 1:i + 1]
        subNum, _ := strconv.Atoi(sub)
        if subNum > 0 && num % subNum == 0 {
            result++
        }
    }
    
    return result
}