Leetcode 326. Power of Three
2016-01-25 13:01
330 查看
Given an integer, write a function to determine if it is a power of three.
这个是Power of two 的兄弟题,他的兄弟可以用Bit Manipulation做,但是它不可以
这里用了DFS搜索做
public class Solution {
public boolean isPowerOfThree(int n) {
if(n == 0)
return false;
if(n == 1)
return true;
return n%3 == 0 && isPowerOfThree(n/3);
}
}
这个是Power of two 的兄弟题,他的兄弟可以用Bit Manipulation做,但是它不可以
这里用了DFS搜索做
public class Solution {
public boolean isPowerOfThree(int n) {
if(n == 0)
return false;
if(n == 1)
return true;
return n%3 == 0 && isPowerOfThree(n/3);
}
}
相关文章推荐
- Android基于XMPP Smack openfire 开发的聊天室(六) 【加入房间、权限错误】
- iOS 中如何添加应用自己的字体,使用萍方体
- 实用的第三方插件
- Android基于XMPP Smack openfire 开发的聊天室(五) 【邀请、被邀请】
- 看源代码库
- 快慢指针-----Linked List Cycle II
- Android基于XMPP Smack openfire 开发的聊天室(四) 【创建房间、表单;报文】
- linx性能监控
- Android基于XMPP Smack openfire 开发的聊天室(三) 【新旧记录、踢人】
- Gradle Android 引入os文件的3种方式
- Head First C (前半部分)读书笔记
- c#之转义字符
- qt发布 2
- Android基于XMPP Smack openfire 开发的聊天室(二) 【聊天信息、成员】
- Unix时间戳和北京时间相互转换
- Leetcode Bit Manipulation 题型总结
- Win8.1蓝屏错误代码0×c0000034怎么办
- eclipse快捷键
- 操作引入xml文件的书包(定位到指定节点)
- 使用WPScan扫描wordpress获取用户密码