leetcode Power of Three

leetcode 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?

题目地址: leetcode Power of Three

题目大意:

给定一个整数,判断是否是3的整数幂

思路

方法一

循环判断,每次除以3

C++

Python

方法二

递归

C++

 

Python

 

方法三

取对数

C++

Java

Python

 

本文是leetcode 326 Power of Three 题解,更多本博客题解见 https://www.hrwhisper.me/leetcode-algorithm-solution/

 

本博客若无特殊说明则由 hrwhisper 原创发布
转载请点名出处:细语呢喃 > leetcode Power of Three
本文地址:https://www.hrwhisper.me/leetcode-power-of-three/

听说长得好看的已经打赏了

Leetcode , , . permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *