zoukankan      html  css  js  c++  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 do it without using any loop / recursion?

     1 /*************************************************************************
     2     > File Name: LeetCode326.c
     3     > Author: Juntaran    
     4     > Mail: Jacinthmail@gmail.com
     5     > Created Time: 2016年05月10日 星期二 02时42分09秒
     6  ************************************************************************/
     7 
     8 /*************************************************************************
     9     
    10     Power of Three
    11     
    12     Given an integer, write a function to determine if it is a power of three.
    13 
    14     Follow up:
    15     Could you do it without using any loop / recursion?
    16 
    17  ************************************************************************/
    18 
    19 #include "stdio.h"
    20 
    21 int isPowerOfThree(int n) {
    22     double tmp = log10(n)/log10(3);
    23     return tmp == (int)tmp ? 1 : 0;
    24 }
    25 
    26 int main()
    27 {
    28     int n = 9;
    29     int ret = isPowerOfThree(n);
    30     printf("%d
    ",ret);
    31     
    32     n = 10;
    33     ret = isPowerOfThree(n);
    34     printf("%d
    ",ret);
    35     
    36     return 0;
    37 }
  • 相关阅读:
    C# 解决组合优化问题
    <@spring.message "index.title"/>
    服务容错处理库Polly使用
    Pycharm使用入门
    JS知识点
    design pattern
    java的NIO
    Promise
    Docker Compose + Spring Boot + Nginx + Mysql
    苹果开发者账号如何多人协作进行开发和真机调试XCode
  • 原文地址:https://www.cnblogs.com/Juntaran/p/5479112.html
Copyright © 2011-2022 走看看