MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / HappyNumber

Class HappyNumber

Java/Happy-Number.java:1–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class HappyNumber {
2 public boolean isHappy(int n) {
3 int num1, num2;
4
5 num1 = num2 = n;
6 do
7 {
8 num1 = SquareSum(num1);
9
10
11 num2 = SquareSum(SquareSum(num2));
12
13 }
14 while (num1 != num2);
15
16 return (num1 == 1);
17}
18
19
20static int SquareSum(int n)
21 {
22 int square = 0;
23 while (n!= 0)
24 {
25 square += (n % 10) * (n % 10);
26 n /= 10;
27 }
28 return square;
29 }
30
31}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected