标签:
弗洛伊德判环!
1 class Solution { 2 public: 3 int change(int n){ 4 int ans = 0; 5 for ( ; n!=0 ; ans+= (n%10)*(n%10),n/=10); 6 return ans; 7 } 8 bool isHappy(int n) { 9 int one = n; 10 int two = n; 11 while(1){ 12 one = change(one); 13 two = change(change(two)); 14 if(one == 1 || two == 1) return true; 15 if(one == two) return false; 16 } 17 18 } 19 };
Leetcode 202 Happy Number 弗洛伊德判环
标签:
原文地址:http://www.cnblogs.com/onlyac/p/5133010.html