Leetcode 326. Power of Three (Easy) (cpp)
2016-07-14 10:52
465 查看
Leetcode 326. Power of Three (Easy) (cpp)
Tag: Math
Difficulty: Easy
Tag: Math
Difficulty: Easy
/* 326. Power of Three (Easy) Given an integer, write a function to determine if it is a power of three. Follow up: Could you do it without using any loop / recursion? */ class Solution { public: bool isPowerOfThree(int n) { if (n <= 0) return false; if(n == 1) return true; if(n % 3 == 0) return isPowerOfThree(n / 3); return false; } }; class Solution { public: bool isPowerOfThree(int n) { if(n > 0) return 1162261467 % n == 0; else return false; } };
相关文章推荐
- ScyllaDB:用 C++ 重写后的 Cassandra ,性能提高了十倍
- 趣味100道C语言程序num four
- C语言的一些特殊用法(#define)
- C++ 变长参数函数小结
- c++ 引用
- C语言中函数strcpy ,strncpy ,strlcpy的用法【转】
- C语言 程序 去最高最低分的评分 , 偏心和不偏心的评分
- 为什么嵌入式要用C语言编写?
- 字符串的排列组合问题
- 结构体sort快速排序
- c语言getchar()函数使用总结
- 《C++ Primer Plus》14.4 类模板 学习笔记
- c语言格式化输出函数printf()
- C++Primer(5th)第六章page190代码详解
- 详解C语言中的fopen()函数和fdopen()函数
- C语言fopen()函数:打开一个文件并返回文件指针
- C语言 数据类型和变量
- C语言setvbuf()函数:设置文件流的缓冲区
- C语言中,FILE是关键字吗?
- C语言setbuf()函数:把缓冲区与流相关联