当前位置:网站首页>[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));
}
}
边栏推荐
猜你喜欢
随机推荐
MySQL中对于事务的理解
利用SecureCRTPortable远程连接虚拟机
基准环路增益与相位裕度的测量
内部字段分隔符
配置筛选机
牛客月赛-分组求对数和
Congratulations on the release of friends' new book (send welfare)
详解Kubernetes网络模型
Understanding of indexes in MySQL
【目标跟踪】|单目标跟踪指标
Favorite transaction code management tool in SAP GUI
FFMpeg学习笔记
The median salary of TSMC's global employees is about 460000, and the CEO is about 8.99 million; Apple raised the price of iPhone in Japan; VIM 9.0 release | geek headlines
“信任机器”为发展赋能
Learn MySQL from scratch - database and data table operations
Configure filter
Pytorch nn. functional. Simple understanding and usage of unfold()
Friendly serial assistant tutorial_ How to configure friendly serial port debugging assistant - tutorial on using friendly serial port debugging assistant
【日常训练】326. 3 的幂
Appium自动化测试基础 — APPium安装(一)