CodeMentor.
Ask AIProblemsLearnC++TCSCore CSHRProgress
0Lv 1
ProblemsHashing

Happy Number

Easy
LeetCode
7/8
EasyHashingLeetCode #202

Happy Number

Replace n by sum of squares of digits. Happy if you reach 1. Detect cycles with a set (or Floyd).

Examples

Example 1

Input

19

Output

true
Example 2

Input

2

Output

false

Stuck? Take a nudge

C++17Autosaves