【leetcode】Power of Three
2016-06-02 13:46
429 查看
Question
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?
Code
#include<iostream> using namespace std; class Solution { public: bool isPowerOfThree(int n) { double res = log10(n) / log10(3); return (res - (int)res == 0) ? true:false; } }; int main() { Solution so; int n = 9; cout << so.isPowerOfThree(n) << endl; system("pause"); return 0; }
相关文章推荐
- 设计模式之Template Method模式(模板方法模式)
- java io流
- HTML页面上获取鼠标的位置(备忘)
- 前端发送的多层嵌套json解析
- 什么是第一,第二,第三范式
- ADC模数转换器工作原理及分类
- 使用Fiddler对iPhone苹果手机进行数据抓包分析
- Spring Boot笔记
- 分类器的评估与选择
- IIS 启用w3wp.exe调试 没有找到w3wp进程
- AndroidStudio配置SVN以及使用代码管理
- C#—实验9.6和9.7
- Oracle数据库两种操作
- C语言的指针(进阶篇章之一)
- NEFU 115 斐波那契的整除
- CF 开车找房子
- RHRL7.0安装RAC11.2.0.4----Error in invoking target 'agent nmhs' of makefile '/u01/app/oracle/product/1
- IPv6进阶
- 源码编译php-5 报错整理
- redisDB