Leetcode----326. Power of three (Java)

Source: Internet
Author: User

1  PackageisPowerOfThree326;2 /*3 Given An integer, write a function to determine if it is a power of three.4  */5  Public classSolution {6     /*7 //The problem is understood incorrectly and understood as 3 times8 Public Static Boolean ispowerofthree (int n) {9 if (n==1)Ten return true; One else{ A for (int i=2;i<=math.sqrt (n); i++) { - if (n%i==0) { - n=n/i; the if (n%i==0) { - n=n/i; - if (n%i==0) { - n=n/i; + return Ispowerofthree (n); -                         }     + Else A return false; at                     } - return false; -                 } -             } - return false; -         } in     } -     */ to      Public Static BooleanIspowerofthree (intN) { +         if(n==1) -             return true; the         Else if(n==0) *             return false; $         Else if(n%3==0){Panax NotoginsengN=n/3; -             returnispowerofthree (n); the         } +         Else A             return false; the              +              -     } $      Public Static voidMain (string[] args) { $         //TODO auto-generated Method Stub -System.out.println (Ispowerofthree (-3)); -     } the  -}

Leetcode----326. Power of three (Java)

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.