Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Leetcode] Power of three #42

Open
lpatmo opened this issue May 21, 2019 · 1 comment
Open

[Leetcode] Power of three #42

lpatmo opened this issue May 21, 2019 · 1 comment

Comments

@lpatmo
Copy link
Member

lpatmo commented May 21, 2019

Given an integer, write a function to determine if it is a power of three.

Example 1:

Input: 27
Output: true
Example 2:

Input: 0
Output: false
Example 3:

Input: 9
Output: true
Example 4:

Input: 45
Output: false

@lpatmo
Copy link
Member Author

lpatmo commented May 21, 2019

var isPowerOfThree = function(n) {
    if (n < 1) {
        return false;
    }
    while (n > 1) {
        if (n % 3 !== 0) {
            return false;
        }
         n = n/3;
        
    }
    return true;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant