```
bool isHappy( int n ) {
if( n == 1 ) return 1;
unordered_map< int, bool > m;
int i, temp;
m[n] = 1;
for( ;; ) {
temp = 0;
for( ; n; n /= 10 ) {
i = n % 10;
temp += i * i;
}
if ( temp == 1 ) return 1;
if( m[temp]++ ) return 0;
n = temp;
}
}
```