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的更多相关文章

  1. leetcode 326. Power of Three(不用循环或递归)

    leetcode 326. Power of Three(不用循环或递归) Given an integer, write a function to determine if it is a pow ...

  2. 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. 不使用循环或递归判断一个数是否为3的幂(leetcode 326)

    326. Power of ThreeGiven an integer, write a function to determine if it is a power of three. Follow ...

  4. 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 ...

  5. [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 ...

  6. Java实现 LeetCode 326 3的幂

    326. 3的幂 给定一个整数,写一个函数来判断它是否是 3 的幂次方. 示例 1: 输入: 27 输出: true 示例 2: 输入: 0 输出: false 示例 3: 输入: 9 输出: tru ...

  7. 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 ...

  8. Leetcode 326 Power of Three 数论

    判断一个数是否是3的n次幂 这里我用了一点巧,所有的int范围的3的n次幂是int范围最大的3的n次幂数(即3^((int)log3(MAXINT)) =  1162261467)的约数 这种方法是我 ...

  9. 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 ...

随机推荐

  1. 第二百七十四、五、六天 how can I 坚持

    三天小长假这么快就过去了,好快啊.基本都是在济南过的. 元旦.坐车回济南.下午在万科新里程看了一下午房子,没有买啊,93的现在八千六七,有点贵啊,户型也不是自己喜欢的. 晚上一块吃了个饭,还行,晚上在 ...

  2. work8

    使用裸指针: #include <iostream>#include <memory>#include <stdio.h>#include <cstring& ...

  3. #maven系列(4)-maven插件的介绍

    1. 简介 在Maven设计中,实际的任务都是交由插件完成的,这种思想和设计模式中的模板方法非常类似,模板方法模式在父类中定义算法的整体结构,子类可以通过实现或者重写父类的方法来控制实际的行为,这样既 ...

  4. Spring入门(7)-自动检测Bean

    Spring入门(7)-自动检测Bean 本文介绍如何自动检测Bean. 0. 目录 使用component-scan自动扫描 为自动检测标注Bean 1. 使用component-scan自动扫描 ...

  5. thymeleaf的属性优先级

    所有Thymeleaf属性定义一个数字优先,建立他们的顺序执行的标签.这个顺序是: Order Feature Attributes 1 Fragment inclusion th:includeth ...

  6. [iOS基础控件 - 6.12.3] @property属性 strong weak copy

    A.概念 @property 的修饰词   strong: 强指针/强引用(iOS6及之前是retain) weak: 弱智真/弱引用(iOS6及之前是assign)   默认情况所有指针都是强指针 ...

  7. Spring启动时加载数据

    程序中也许有会有许多常用的,不会经常更改的数据,我们可以在程序初始化的时候就把他们加载,就不用频繁的加载或者查询. 以下是几个常用的,有COPY收集的,也有自己弄. 1. 实现BeanPostProc ...

  8. Docker基本命令

    1.搜索Docker镜像 docker search <镜像名> 2.获取镜像 docker pull <镜像名> 3.查看本地镜像 docker images 4.删除镜像 ...

  9. shape中的属性大全

    首先,看看事例代码 <shape> <!-- 实心 --> <solid android:color="#ff9999"/> <!-- 渐 ...

  10. 深入了解 Dojo 的服务器推送技术

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...