Given an integer, write a function to determine if it is a power of three. 题意分析: n^m,n叫做幂,m叫做次方。32位int型,当n == 19是,3^n最大。因此要判断一个数num是否为a power of three,可以通过3 ^ n % num。 123456 class Solution {public: bool (int n) { return n <= 0 ? false : (((int)pow(3,19)) % n == 0); }}; 赞微海报分享
近期评论