当前位置:网站首页>【日常训练】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));
}
}
边栏推荐
- String type conversion BigDecimal, date type
- 完全注解的ssm框架搭建
- RestTemplate 远程调用工具类
- Pytorch sharpening chapter | argmax and argmin functions
- Several ways of writing main function in C
- C#/VB.NET 给PDF文档添加文本/图像水印
- 灵动微 MM32 多路ADC-DMA配置
- Smart micro mm32 multi-channel adc-dma configuration
- #yyds干货盘点# 解决名企真题:扭蛋机
- Unity 使用Sqlite
猜你喜欢
随机推荐
Pytorch sharpening chapter | argmax and argmin functions
Qtreeview+qabstractitemmodel custom model: the third of a series of tutorials [easy to understand]
快乐数[环类问题之快慢指针]
微软、哥伦比亚大学|GODEL:目标导向对话的大规模预训练
Recent public ancestor offline practice (tarjan)
Relationship and difference between enterprise architecture and project management
【单体】流辰信息I-BPSv3服务器推荐配置
Yyds dry goods inventory # solve the real problem of famous enterprises: egg twisting machine
Clean up system cache and free memory under Linux
【juc学习之路第9天】屏障衍生工具
Smart micro mm32 multi-channel adc-dma configuration
Redis配置与优化
Count the number of each character in the character
详解JMM
[ecological partner] Kunpeng system engineer training
Chapter 9 Yunji datacanvas company has been ranked top 3 in China's machine learning platform market
Application of real estate management based on 3D GIS
【生态伙伴】鲲鹏系统工程师培训
Business visualization - make your flowchart'run'up
Mysql——》Innodb存储引擎的索引