Happy Number
Aug 12, 2016
https://leetcode.com/problems/happy-number/
The key point for this question is to use a Set
to keep recording
the number generated with each iteration. If we can’t add the new number
to the Set
, the endless loop begins: return false. Another trick is to
get the last digit of a number, the
i = n % 10; // get the last digit
n = n / 10; // push one position right
would do that.
|
|