当前位置:网站首页>[daily training] 326 Power of 3
[daily training] 326 Power of 3
2022-07-01 22:50:00 【Puppet__】
subject
Given an integer , Write a function to determine if it is 3 Power square . If it is , return true ; otherwise , return false .
Integers n yes 3 To the power of : There are integers x bring n == 3x
Example 1:
Input :n = 27
Output :true
Example 2:
Input :n = 0
Output :false
Example 3:
Input :n = 9
Output :true
Example 4:
Input :n = 45
Output :false
Tips :
-231<= n <= 231 - 1
Code
package dayLeetCode;
public class dayleetcode326 {
public boolean isPowerOfThree(int n) {
if (n == 0){
return false;
}
while (n != 0 && n % 3 == 0){
n /= 3;
}
if (n == 1){
return true;
}else {
return false;
}
}
public static void main(String[] args) {
dayleetcode326 obj = new dayleetcode326();
System.out.println(obj.isPowerOfThree(27));
}
}
边栏推荐
- Explain kubernetes network model in detail
- Use three JS realize the 'ice cream' earth, and let the earth cool for a summer
- Talk about what parameters ZABBIX monitors
- twenty million two hundred and twenty thousand seven hundred and one
- MySQL中对于事务的理解
- 阿洛迷茫后的思考
- internal field separator
- 数字货币:影响深远的创新
- Efficiency improvement - encourage personalized container development environment
- Wechat open platform scanning code login [easy to understand]
猜你喜欢
随机推荐
性能测试计划怎么编写
“信任机器”为发展赋能
MySQL MHA high availability configuration and failover
详解Kubernetes网络模型
【c语言】malloc函数详解[通俗易懂]
深度学习--数据操作
【日常训练】66. 加一
Kubernetes创建Service访问Pod
聊一聊Zabbix都监控哪些参数
Redis configuration and optimization
激发新动能 多地发力数字经济
阿洛迷茫后的思考
Clean up system cache and free memory under Linux
Mixconv code
3DE 资源没东西或不对
Resttemplate remote call tool class
Single step debugging analysis of rxjs observable of operator
Appium自动化测试基础 — 补充:Desired Capabilities参数介绍
好友新书发布,祝贺(送福利)
Origin2018安装教程「建议收藏」