isPowerOf3 static method

bool isPowerOf3(
  1. int n
)

Checks if n is potĂȘncia de 3

Implementation

static bool isPowerOf3(int n) {
  if (n <= 0) return false;
  while (n > 1) {
    if (n % 3 != 0) return false;
    n ~/= 3;
  }
  return n == 1;
}