PowerOfThree

  • 2022-12-14
  • 浏览 (585)

PowerOfThree.java 源码

package datastructure.array.leetcode;

/**
 * 3的幂次方
 */
public class PowerOfThree {

    /**
     * 迭代法
     */
    public boolean isPowerOfThree(int n) {
        while (n >= 3) {
            if (n % 3 != 0) {
                return false;
            }
            n /= 3;
        }
        return n == 1;
    }
}

你可能感兴趣的文章

BestTimeBuySellStock

BestTimeBuySellStockII

BullsAndCows

0  赞