Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 378 Bytes

202.Happy_Number.md

File metadata and controls

24 lines (20 loc) · 378 Bytes

Create a function to get digits pow

func isHappy(n int) bool {
	set := map[int]bool{}
	for n!=1 && !set[n] {
        n, set[n] = GetSum(n), true
	}
	return n == 1
}

func GetSum(n int) int {
	var sum int
	for n > 0 {
		sum += (n % 10) * (n % 10)
		n = n / 10
	}
	return sum
}