标签:
public class Solution { public bool IsHappy(int n) { var digs = n.ToString(); var hash = new Dictionary<int, bool>(); while(true){ int r = 0; for(var i = 0;i < digs.Length; i++){ var x = int.Parse(digs[i].ToString()); r += x * x; } if(r == 1){ return true; } if(!hash.ContainsKey(r)){ hash.Add(r, true); digs = r.ToString(); } else{ return false; } } } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/lan_liang/article/details/49108359