Tips:
The first time there is no AC because there is no judgment 1 for this particular number, the other is nothing too difficult to place, the code and comments are as follows:
public class Solution202 {public boolean ishappy (int n) { int nn = n,temp = 0; set<integer> set = new Hashset<integer> (); <span style= "White-space:pre" ></span>// Check whether the set is returned to the starting point set.add (n); <span style= "White-space:pre" ></span>//add N to if (n = = 1) <span style= "White-space:pre" ></SPAN>//1 need to first determine the return true; while (temp!=1) { temp = 0; while (NN! = 0) {<span style= "White-space:pre" ></span>//everyone's squared and temp + = Math.pow (nn%, 2); nn = NN/10; } if (Set.contains (temp)) <span style= "White-space:pre" ></span> return false; Set.add (temp); nn = temp; } return True;<span style= "White-space:pre" ></span>//if Loop end is happy number }}
Happy problem "leetcode202"