题解 | #奶牛快乐数#
奶牛快乐数
https://www.nowcoder.com/practice/d91cec70c7724a7dbcea02ed25bdeaee
package main
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param n int整型
* @return bool布尔型
*/
func isHappy( n int ) bool {
// write code here
count :=make(map[int]bool)
count[n]=true
temp :=0
for n!=1{
for n!=0{
temp=(n%10)*(n%10)+temp
n=n/10
}
if _,ok :=count[temp];ok{
return false
}
count[temp]=true
n=temp
temp=0
}
return true
}


华为HUAWEI工作强度 1383人发布