Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Solution {
- public:
- bool isHappy(int n) {
- while (n > 6) {
- int res = 0;
- while (n > 0) {
- res += (n % 10) * (n % 10);
- n /= 10;
- }
- n = res;
- }
- return n == 1;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement