Update ctl templates sorting

This commit is contained in:
halfrost
2021-06-26 18:20:04 +08:00
parent e216ed4430
commit f663cec583
15 changed files with 177 additions and 133 deletions

View File

@ -1,32 +1,26 @@
package leetcode
func getSquareOfDigits(n int) int {
squareOfDigits := 0
temporary := n
for temporary != 0 {
remainder := temporary % 10
squareOfDigits += remainder * remainder
temporary /= 10
}
return squareOfDigits
}
func isHappy(n int) bool {
record := map[int]int{}
for n != 1 {
record[n] = n
n = getSquareOfDigits(n)
for _, previous := range record {
if n == previous {
return false
}
}
}
return true
}
func getSquareOfDigits(n int) int {
squareOfDigits := 0
temporary := n
for temporary != 0 {
remainder := temporary % 10
squareOfDigits += remainder * remainder
temporary /= 10
}
return squareOfDigits
}