leetcode-326-Power of Three
2016-01-11 23:22
471 查看
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?
Credits:
Special thanks to @dietpepsi for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
判断一个数是否为3的次方
C++
python
Follow up:
Could you do it without using any loop / recursion?
Credits:
Special thanks to @dietpepsi for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
判断一个数是否为3的次方
C++
class Solution { public: bool isPowerOfThree(int n) { if ( !n ) return false ; while ( n != 1 ) { if ( n % 3 ) return false ; else n = n / 3 ; } return true ; } };
python
class Solution(object): def isPowerOfThree(self, n): """ :type n: int :rtype: bool """ if n == 0 : return False while n != 1 : if ( n % 3 != 0 ) : return False else : n = n / 3 ; return True
相关文章推荐
- MongoDB安装、管理工具、操作
- Camera Function - 摄像头功能说明
- CocoaPods的下载和安装及常见问题
- jQuery 核心
- Java JSON库Jackson 2.x新变化一览
- 编译php7遇到的内存不足
- Android 操作SQLite基本用法介绍
- 作为一场新的挑战。
- Code First添加一个现有数据库中的表
- ASP.NET第一部分总结
- cocos2dx 音频模块分析(1):背景音乐
- android异步加载之Handler、AsyncTask(一)
- 将软键盘的回车按钮变为搜索按钮
- 开源APP CoCoin
- Android studio正确配置AndroidAnnotation注解
- Android应用程序互保方案
- android studio的assets目录下存放ttf字体格式的问题
- 学习shell编程笔记(二)
- 二叉树的最小深度
- TOMCAT学习点滴