每天一道LeetCode--326. Power of Three
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?
public class Solution {
public boolean isPowerOfThree(int n) {
int num=n;
while(num>0&&num%3==0)
num/=3;
return num==1;
}
//return n > 0 && (1162261467 % n == 0);
}
每天一道LeetCode--326. Power of Three的更多相关文章
- leetcode 326. Power of Three(不用循环或递归)
leetcode 326. Power of Three(不用循环或递归) Given an integer, write a function to determine if it is a pow ...
- 39. leetcode 326. Power of Three
326. Power of Three Given an integer, write a function to determine if it is a power of three. Follo ...
- [LeetCode] 326. Power of Three 3的次方数
Given an integer, write a function to determine if it is a power of three. Follow up:Could you do it ...
- LeetCode 326 Power of Three
Problem: Given an integer, write a function to determine if it is a power of three. Could you do it ...
- Java [Leetcode 326]Power of Three
题目描述: Given an integer, write a function to determine if it is a power of three. Follow up:Could you ...
- LeetCode 326 Power of Three(3的幂)(递归、Log函数)
翻译 给定一个整型数,写一个函数决定它是否是3的幂(翻译可能不太合适-- 跟进: 你能否够不用不论什么循环或递归来完毕. 原文 Given an integer, write a function t ...
- leetcode 326 Power of Three (python)
原题: Given an integer, write a function to determine if it is a power of three. Follow up: Could you ...
- Leetcode 326 Power of Three 数论
判断一个数是否是3的n次幂 这里我用了一点巧,所有的int范围的3的n次幂是int范围最大的3的n次幂数(即3^((int)log3(MAXINT)) = 1162261467)的约数 这种方法是我 ...
- [LeetCode] 326. Power of Three + 342. Power of Four
这两题我放在一起说是因为思路一模一样,没什么值得研究的.思路都是用对数去判断. /** * @param {number} n * @return {boolean} */ var isPowerOf ...
- [LeetCode] 231. Power of Two 2的次方数
Given an integer, write a function to determine if it is a power of two. Example 1: Input: 1 Output: ...
随机推荐
- iOS 通知中心 NSNotificationCenter
iOS开发中,每个app都有一个通知中心,通知中心可以发送和接收通知. 在使用通知中心 NSNotificationCenter之前,先了解一下通知 NSNotification. NSNotific ...
- linq to sql 三层架构中使用CRUD操作
/// <summary> /// 数据层 /// </summary> public partial class GasBottles : IGasBottles { #re ...
- [ALGO-3] K好数
算法训练 K好数 时间限制:1.0s 内存限制:256.0MB 问题描写叙述 假设一个自然数N的K进制表示中随意的相邻的两位都不是相邻的数字,那么我们就说这个数是K好数.求L位K进制数中K好数 ...
- DuiLib(四)——控件绘制
duilib的所有控件均绘制在唯一的真实窗口之中,本篇就具体看下这个绘制的过程.所有的绘制过程均在WM_PAINT消息处理过程中完成.由窗口及消息篇可以看到,窗口消息处理最终流到了CPaintMana ...
- HDU 4819 Mosaic 二维线段树
Mosaic Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- Visual Prolog 的 Web 专家系统 (9)
GENI的核心 -- 推理机(3)一些谓词 为了集中注意力.较好地分析GENI推理机核心程序,应该做些准备工作,弄明确一些起辅助作用的谓词功能. is_htmlfile(Rulexpl) is_htm ...
- Jquery中$与$.fn的差别
当今web开发往往离不开Jquery的使用,Jquery以其简洁的使用方式.良好的浏览器兼容性赢得了软件研发同行的青睐,作为当中的一员,自然也不例外,虽然刚開始时非常排斥Jquery,今天我谈一下对J ...
- Python2.7.3移除字符串中重复字符(一)
移除重复字符很简单,这里是最笨,也是最简单的一种.问题关键是理解排序的意义: # coding=utf-8 #learning at jeapedu in 2013/10/26 #移除给定字符串中重复 ...
- 归并排序的C语言实现
归并排序的核心思想是 Divide-and-Conquer 算法,即将要解决的size为n的问题,分成a个size为n/b的子问题,这些子问题的结果经过O(n^d)的时间复杂度合并,即可解决最初的问题 ...
- 获取设备上全部系统app信息
在获取android设备的全部程序信息一文中介绍了获取手机上全部app信息的方法,以下介绍过滤掉系统app的方法: MainActivity: package com.home.getsysapp; ...