Leetcode Note: Go - Sum of Digits in Base K

Sum of Digits in Base K - LeetCode
https://leetcode.com/problems/sum-of-digits-in-base-k/

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

回答

Go Solution | Easy - Sum of Digits in Base K - LeetCode
https://leetcode.com/problems/sum-of-digits-in-base-k/solutions/1394442/go-solution-easy/

func sumBase(n int, k int) int {
    sum := 0
    
    for n > 0 {
        sum += n % k
        n /= k
    }
    
    return sum
}