Leetcode 326. Power of Three
来源:互联网 发布:行业大盘数据分析 编辑:程序博客网 时间:2024/05/18 00:52
Given an integer, write a function to determine if it is a power of three.
Follow up:
Could you do it without using any loop / recursion?
Credits:
Special thanks to @dietpepsi for adding this problem and creating all test cases.
Subscribe to see which companies asked this question
public class Solution { public boolean isPowerOfThree(int n) { if(n == 0) { return false; } if(n == 1) { return true; } while(n % 3 == 0) { n /= 3; } if(n == 1) { return true; } else { return false; } }}
只写出了用迭代的方法,Google了一下,找到了python版本的写法,要用到Math.log()。但是无奈,Java的标准库中并没有以3为底的log函数。
0 0
- [leetcode]326. Power of Three
- Leetcode 326. Power of Three
- Leetcode 326. Power of Three
- [leetcode] - 326. Power of Three
- 326. Power of Three LeetCode
- LeetCode ||326. Power of Three
- [LeetCode]326. Power of Three
- [leetcode] 326. Power of Three
- LeetCode *** 326. Power of Three
- leetcode 326. Power of Three
- 326.[LeetCode]Power Of Three
- LeetCode 326. Power of Three
- #leetcode#326. Power of Three
- Leetcode 326. Power of Three
- Leetcode 326. Power of Three
- leetcode 326. Power of Three
- LeetCode 326. Power of Three
- [leetcode] 326. Power of Three
- 19Java语法回顾之反射
- Redis 横向扩展案例
- Hadoop YARN学习监控JVM和实时监控Ganglia、Ambari(5)
- 《剑指offer》——两个链表的第一个公共结点
- unity 中抗锯齿设置
- Leetcode 326. Power of Three
- 如何利用fsolve求方程组[matlab]
- 介绍两个分布式数据库开源系统
- JAVA Exception 处理
- 程序员,一个吃青春饭的行业
- android-gpuimage-master 编译失败
- Struts2-表单验证的两种方式
- java中利用正则去除html标签
- IEEE Std 802.11TM-2012 WLAN MAC and PHY specifications-第7章 物理层规格04