Happy problem "leetcode202"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.