当前位置:网站首页>【日常训练】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));
}
}
边栏推荐
- MySQL learning notes - SQL optimization of optimization
- Is PMP certificate really useful?
- Mysql——》MyISAM存储引擎的索引
- Count the number of each character in the character
- Four methods of JS array splicing [easy to understand]
- PHP reflective XSS, reflective XSS test and repair
- The difference between NiO and traditional IO
- Qtreeview+qabstractitemmodel custom model: the third of a series of tutorials [easy to understand]
- Internet of things RFID, etc
- Copy ‘XXXX‘ to effectively final temp variable
猜你喜欢
随机推荐
GaussDB(DWS)主动预防排查
并发编程系列之FutureTask源码学习笔记
Why must digital transformation strategies include continuous testing?
Use of vscode
mysql 学习笔记-优化之SQL优化
spark analyze命令使用及其作用 map join broadcast join 广播join
Learn MySQL from scratch - database and data table operations
Gaussdb (DWS) active prevention and troubleshooting
Which securities company should we choose to open an account for flush stock? Is it safe to open an account with a mobile phone?
PHP reflective XSS, reflective XSS test and repair
Internet of things RFID, etc
List announced | outstanding intellectual property service team in China in 2021
String type conversion BigDecimal, date type
ICML2022 | 基于元语义正则化的介入性对比学习
小 P 周刊 Vol.11
[STM32] stm32cubemx tutorial II - basic use (new projects light up LED lights)
Four methods of JS array splicing [easy to understand]
CNN convolution neural network principle explanation + image recognition application (with source code) [easy to understand]
【MySQL】索引的创建、查看和删除
企业架构与项目管理的关联和区别









