aboutsummaryrefslogtreecommitdiff
path: root/power_3.cpp
blob: f92e6e3e0d854a74cffc984176e0588f9ec0a351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "leetcode.h"

class Solution {
public:
  bool isPowerOfThree(int n) {
    if (n > 1)
      while (n % 3 == 0)
        n /= 3;
    return n == 1;
  }
};

int main() {
  Solution obj;
  if (obj.isPowerOfThree(27))
    cout << "true";
  else
    cout << "false";
}