当前位置:网站首页>【日常训练】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));
}
}
边栏推荐
- linux下清理系统缓存并释放内存
- 【juc学习之路第8天】Condition
- RestTemplate 远程调用工具类
- 13th Blue Bridge Cup group B national tournament
- MySQL系列之事务日志Redo log学习笔记
- Burpsuite simple packet capturing tutorial [easy to understand]
- Which securities company should we choose to open an account for flush stock? Is it safe to open an account with a mobile phone?
- Separate the letters and numbers in the string so that the letters come first and the array comes last
- Unity 使用Sqlite
- Show member variables and methods in classes in idea
猜你喜欢
Spark interview questions
【JetCache】JetCache的使用方法与步骤
I received a letter from CTO inviting me to interview machine learning engineer
从零开始学 MySQL —数据库和数据表操作
功能测试报告的编写
并发编程系列之FutureTask源码学习笔记
C#/VB.NET 给PDF文档添加文本/图像水印
Indicator trap: seven KPI mistakes that it leaders are prone to make
EasyExcel 复杂数据导出
MySQL learning notes - SQL optimization of optimization
随机推荐
Why does blocprovider feel similar to provider?
Icml2022 | interventional contrastive learning based on meta semantic regularization
C#/VB.NET 给PDF文档添加文本/图像水印
使用闭包实现点击按钮切换 toggle
What is the difference between consonants and Initials? (difference between initials and consonants)
Ida dynamic debugging apk
Smart micro mm32 multi-channel adc-dma configuration
CSDN购买的课程从哪里可以进入
Is PMP certificate really useful?
[STM32] stm32cubemx tutorial II - basic use (new projects light up LED lights)
地图其他篇总目录
Recent public ancestor (LCA) online practices
CIO's discussion and Analysis on the definition of high-performance it team
Medium pen test questions: flip the string, such as ABCD, print out DCBA
keras训练的H5模型转tflite
Redis配置与优化
Four methods of JS array splicing [easy to understand]
【MySQL】数据库优化方法
信标委云原生专题组组长,任重道远!
性能测试计划怎么编写