Files
coding-practice/202508/326 isPowerOfThree/C#/Program.cs

21 lines
502 B
C#

public class Solution {
public bool IsPowerOfThree(int n) {
if(n <= 0)
return false;
if(n == 1)
return true;
if(n % 3 != 0)
return false;
return IsPowerOfThree(n/3);
}
}
class program{
static void Main(){
var Solution = new Solution();
Console.WriteLine(Solution.IsPowerOfThree(9));
Console.WriteLine(Solution.IsPowerOfThree(0));
Console.WriteLine(Solution.IsPowerOfThree(-1));
}
}