当前位置:网站首页>【日常训练】326. 3 的幂
【日常训练】326. 3 的幂
2022-07-01 21:47:00 【Puppet__】
题目
给定一个整数,写一个函数来判断它是否是 3 的幂次方。如果是,返回 true ;否则,返回 false 。
整数 n 是 3 的幂次方需满足:存在整数 x 使得 n == 3x
示例 1:
输入:n = 27
输出:true
示例 2:
输入:n = 0
输出:false
示例 3:
输入:n = 9
输出:true
示例 4:
输入:n = 45
输出:false
提示:
-231<= n <= 231 - 1
代码
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));
}
}
边栏推荐
- EasyExcel 复杂数据导出
- QT uses ffmpeg4 to convert the qimage of ARGB to yuv422p
- Learn MySQL from scratch - database and data table operations
- 13th Blue Bridge Cup group B national tournament
- Interview question: what is the difference between MySQL's Union all and union, and how many join methods MySQL has (Alibaba interview question) [easy to understand]
- 【JetCache】JetCache的使用方法与步骤
- Recent public ancestor offline practice (tarjan)
- MQ learning notes
- Unity 使用Sqlite
- Clean up system cache and free memory under Linux
猜你喜欢
Mysql——》Innodb存储引擎的索引
Mask wearing detection method based on yolov5
Basic operation of binary tree
园区全光技术选型-中篇
100年仅6款产品获批,疫苗竞争背后的“佐剂”江湖
"The silk road is in its youth and looks at Fujian" is in the hot collection of works in the Fujian foreign youth short video competition
Learn MySQL from scratch - database and data table operations
linux下清理系统缓存并释放内存
Indicator trap: seven KPI mistakes that it leaders are prone to make
Training on the device with MIT | 256Kb memory
随机推荐
Can you get a raise? Analysis on gold content of PMP certificate
Mysql——》索引存储模型推演
MySQL的存储过程
详解LockSupport的使用
flink sql-client 使用 对照并熟悉官方文档
The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner
What is the difference between consonants and Initials? (difference between initials and consonants)
linux下清理系统缓存并释放内存
三翼鸟两周年:羽翼渐丰,腾飞指日可待
高攀不起的希尔排序,直接插入排序
Application of real estate management based on 3D GIS
Interview question: what is the difference between MySQL's Union all and union, and how many join methods MySQL has (Alibaba interview question) [easy to understand]
QT uses ffmpeg4 to convert the qimage of ARGB to yuv422p
【图像分割】2021-SegFormer NeurIPS
Business visualization - make your flowchart'run'up
RestTemplate 远程调用工具类
keras训练的H5模型转tflite
I received a letter from CTO inviting me to interview machine learning engineer
LC669. 修剪二叉搜索树
Airserver mobile phone third-party screen projection computer software