当前位置:网站首页>[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));
}
}
边栏推荐
猜你喜欢

H5 model trained by keras to tflite

Object memory layout

分享一个一年经历两次裁员的程序员的一些感触

SAP UI5 应用开发教程之一百零四 - SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目

Favorite transaction code management tool in SAP GUI

Chen Tianqi's machine learning compilation course (free)

2020-ViT ICLR

MySQL中对于事务的理解

多图预警~ 华为 ECS 与 阿里云 ECS 对比实战

Fiori applications are shared through the enhancement of adaptation project
随机推荐
MySQL数据库详细学习教程
2020-ViT ICLR
激发新动能 多地发力数字经济
使用 Three.js 实现'雪糕'地球,让地球也凉爽一夏
Talk about what parameters ZABBIX monitors
每日刷题记录 (十)
LC501. 二叉搜索树中的众数
Configure filter
447-哔哩哔哩面经1
104. SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目
There is no signal in HDMI in computer games caused by memory, so it crashes
SAP intelligent robot process automation (IRPA) solution sharing
The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner
删除AWS绑定的信用卡账户
内存导致的电脑游戏中显示hdmi无信号 从而死机的情况
Chen Tianqi's machine learning compilation course (free)
flink sql 命令行 连接 yarn
Operation category read is not supported in state standby
MySQL中对于索引的理解
Understanding of indexes in MySQL