码迷,mamicode.com
首页 > 移动开发 > 详细

202. Happy Number

时间:2018-05-22 19:44:06      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:ext   []   ==   win   turn   class   bool   span   color   

 1 static int wing=[]()
 2 {
 3     std::ios::sync_with_stdio();
 4     cin.tie(NULL);
 5     return 0;
 6 }();
 7 
 8 class Solution 
 9 {
10 public:
11     bool isHappy(int n) 
12     {
13         while(n>6)
14         {
15             int next=0;
16             while(n)
17             {
18                 int a=n%10;
19                 next+=a*a;
20                 n/=10;
21             }
22             n=next;
23         }
24         return n==1;
25     }
26 };

找欢乐逗比数,一级一级算,直到最后数字小于6,小于6的数字中,只有1是欢乐数。

202. Happy Number

标签:ext   []   ==   win   turn   class   bool   span   color   

原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9073531.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!