diff --git a/202508/326 isPowerOfThree/C#/Program.cs b/202508/326 isPowerOfThree/C#/Program.cs new file mode 100644 index 0000000..a522990 --- /dev/null +++ b/202508/326 isPowerOfThree/C#/Program.cs @@ -0,0 +1,21 @@ +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)); + } +} \ No newline at end of file diff --git a/202508/326 isPowerOfThree/C#/isPowerOfThree.csproj b/202508/326 isPowerOfThree/C#/isPowerOfThree.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/202508/326 isPowerOfThree/C#/isPowerOfThree.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/202508/326 isPowerOfThree/description.md b/202508/326 isPowerOfThree/description.md new file mode 100644 index 0000000..d4e511c --- /dev/null +++ b/202508/326 isPowerOfThree/description.md @@ -0,0 +1,22 @@ +Given an integer n, return true if it is a power of three. Otherwise, return false. + +An integer n is a power of three, if there exists an integer x such that n == 3x. + + + +Example 1: + +Input: n = 27 +Output: true +Explanation: 27 = 33 +Example 2: + +Input: n = 0 +Output: false +Explanation: There is no x where 3x = 0. +Example 3: + +Input: n = -1 +Output: false +Explanation: There is no x where 3x = (-1). + \ No newline at end of file