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?
/*************************************************************************
> File Name: LeetCode326.c
> Author: Juntaran
> Mail: Jacinthmail@gmail.com
> Created Time: 2016年05月10日 星期二 02时42分09秒
************************************************************************/ /************************************************************************* 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? ************************************************************************/ #include "stdio.h" int isPowerOfThree(int n) {
double tmp = log10(n)/log10();
return tmp == (int)tmp ? : ;
} int main()
{
int n = ;
int ret = isPowerOfThree(n);
printf("%d\n",ret); n = ;
ret = isPowerOfThree(n);
printf("%d\n",ret); return ;
}
LeetCode 326的更多相关文章
- 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 ...
- 不使用循环或递归判断一个数是否为3的幂(leetcode 326)
326. Power of ThreeGiven an integer, write a function to determine if it is a power of three. Follow ...
- LeetCode - 326, 342, 231 Power of Three, Four, and Two
1. 问题 231. Power of Two: 判断一个整数是否是2的n次方,其中n是非负整数 342. Power of Four: 判断一个整数是否是4的n次方,其中n是非负整数 326. Po ...
- [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 ...
- Java实现 LeetCode 326 3的幂
326. 3的幂 给定一个整数,写一个函数来判断它是否是 3 的幂次方. 示例 1: 输入: 27 输出: true 示例 2: 输入: 0 输出: false 示例 3: 输入: 9 输出: tru ...
- 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 ...
- Leetcode 326 Power of Three 数论
判断一个数是否是3的n次幂 这里我用了一点巧,所有的int范围的3的n次幂是int范围最大的3的n次幂数(即3^((int)log3(MAXINT)) = 1162261467)的约数 这种方法是我 ...
- 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 ...
随机推荐
- [转]解决百度统计 gzdecode(): insufficient memory
百度统计API gzdecode($preLogin->retData, strlen($preLogin->retData)) 这段代码会造成一个PHP警告内存不足,解决办法只要换个解压 ...
- PC问题-该虚拟机似乎正在使用中
问题现象:运行VMware Workstation,选中一个虚拟机,运行.卡住了,再运行VMware Workstation时,选中一个虚拟机,提示“该虚拟机似乎正在使用中”. 问题原因:因为上次非正 ...
- jQuery基础学习3——jQuery库冲突
默认情况下,jQuery用$作为自身的快捷方式. jQuery库在其他库之后导入 在其他库和jQuery库都被加载完毕后,可以在任何时候调用jQuery.noConflict()函数来将变量$的控制权 ...
- scons用户指南翻译(附gcc/g++参数详解)
scons用户指南 翻译 http://blog.csdn.net/andyelvis/article/category/948141 官网文档 http://www.scons.org/docume ...
- squid添加用户名密码认证
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...
- GLSL实现Glow效果 [转]
http://blog.csdn.net/a3070173/archive/2008/11/04/3220940.aspx Glow即辉光效果现在已成为3D图形中一个引人注目的特效.本文主要介绍如何使 ...
- HDU 3410 && POJ 3776 Passing the Message 单调队列
题意: 给定n长的数组(下标从1-n)(n个人的身高,身高各不同样 问:对于第i个人,他能看到的左边最矮的人下标.(假设这个最矮的人被挡住了,则这个值为0) 还有右边最高的人下标,同理若被挡住了则这个 ...
- 几种server模型
TCP測试用客户程序 每次执行客户程序,在命令行參数指定server的ip地址,port,发起连接的子进程数,和一个待发送的字符串数据,客户程序将模拟多个客户依据指定的子进程数创建子进程来并发的连接到 ...
- Spring中ClassPathXmlApplicationContext类的简单使用
转自:http://www.cnblogs.com/shyy/archive/2011/09/29/2453057.html 一.简单的用ApplicationContext做测试的话,获得Sprin ...
- Tomcat安装、配置、优化及负载均衡详解
一.常见JavaWeb服务器 1.WebLogic:是BEA公司的产品.WebSphereAS:是IBM公司的产品.JBossAS:红帽公司的产品,可以自行了解 2.Tomcat服 ...