Write a method to determine whether a postive number is **Happy**.

A number is **Happy** (Yes, it is a thing!) if it follows a sequence that ends in 1 after following the steps given below :

Beginning with the number itself, replace it by the sum of the squares of its digits until either the number becomes 1 or loops endlessly in a cycle that does not include 1.

For instance, **19** is a happy number.
**Sequence**:

1^{2} + 9^{2} = 82

8^{2} + 2^{2} = 68

6^{2} + 8^{2} = 100

1^{2} + 0^{2} + 0^{2} = 1

**Example:**

Input : 19 Output: true

Need a **hand?** Try out these hints, one at a time.

Numbers aren't Happy if they "Loop endlessly in a cycle". Knowing that, you should immediately guess that you'll need a buffer of some sort to keep a history of visited numbers. A HashSet is a good choice!

How do you raise a number to a power of 2? Use Math.pow(num,2). One common mistake is using the ^ operator. That is a Bitwise XOR operator!

Loop until a number already exists in the visited set. Inside the loop, compute the expression as stated in the problem. If the result is 1, return true. Otherwise, add this number to the visited set. Outside the loop, simply return false.

public static boolean isHappyNumber(int n) { }

**C**

**Java**

**Python**