- 浏览: 174721 次
- 性别:
- 来自: 济南
文章分类
最新评论
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?
判断一个整数是否为3的幂。如果一个整数是3的幂,那么就可以表示为
3 ^ x = n => log(3^x) = log(n) => xlog(3) = log(n) => x = log(n) / log(3)。我们只需要判断x是否为整数就可以了,代码如下:
Follow up:
Could you do it without using any loop / recursion?
判断一个整数是否为3的幂。如果一个整数是3的幂,那么就可以表示为
3 ^ x = n => log(3^x) = log(n) => xlog(3) = log(n) => x = log(n) / log(3)。我们只需要判断x是否为整数就可以了,代码如下:
public class Solution { public boolean isPowerOfThree(int n) { if(n <= 0) return false; double d = Math.log10(n) / Math.log10(3); return d % 1 == 0 ? true : false; } }
发表评论
-
498. Diagonal Traverse
2019-11-15 13:52 229Given a matrix of M x N eleme ... -
496 Next Greater Element I
2019-11-14 13:50 232You are given two arrays (witho ... -
Word Break II
2016-03-09 03:15 348Given a string s and a dictiona ... -
Insert Interval
2016-03-08 02:11 342Given a set of non-overlapping ... -
Merge Intervals
2016-03-07 05:25 461Given a collection of intervals ... -
Merge k Sorted Lists
2016-03-07 04:03 525Merge k sorted linked lists and ... -
Multiply Strings
2016-03-06 07:27 435Given two numbers represented a ... -
N-Queens II
2016-03-06 03:06 624Follow up for N-Queens problem. ... -
N-Queens
2016-03-06 02:47 435The n-queens puzzle is the prob ... -
First Missing Positive
2016-03-05 03:09 392Given an unsorted integer array ... -
Spiral Matrix
2016-03-04 03:39 522Given a matrix of m x n element ... -
Trapping Rain Water
2016-03-04 02:54 542Given n non-negative integers r ... -
Repeated DNA Sequences
2016-03-03 03:10 379All DNA is composed of a series ... -
Increasing Triplet Subsequence
2016-03-02 02:48 870Given an unsorted array return ... -
Maximum Product of Word Lengths
2016-03-02 01:56 885Given a string array words, fin ... -
LRU Cache
2016-02-29 10:37 560Design and implement a data str ... -
Super Ugly Number
2016-02-29 07:07 612Write a program to find the nth ... -
Longest Increasing Path in a Matrix
2016-02-29 05:56 771Given an integer matrix, find t ... -
Coin Change
2016-02-29 04:39 741You are given coins of differen ... -
Minimum Height Trees
2016-02-29 04:11 635For a undirected graph with tre ...
相关推荐
Application of a Three-level NPC Inverter as a Three-Phase Four-Wire Power Quality Compensator by Generalized 3DSVM.pdf
Power of Three Rectangle Area 数论 Happy Number Ugly Number Ugly Number II Super Ugly Number Fraction to Recurring Decimal Factorial Trailing Zeroes Nim Game 模拟 Reverse Integer Palindrome Number ...
After a summary of the basic structure of a field-oriented controlled three-phase AC drive as well as of a grid voltage orientated controlled wind power plant the inverter control by space vector ...
231 | [Power of Two](https://leetcode.com/problems/power-of-two/) | [C++](./C++/power-of-two.cpp) [Python](./Python/power-of-two.py) | _O(1)_ | _O(1)_ | Easy | LintCode | 260 | [Single Number III]...
Simulation schematic, STATCOM ... In the simulation model to simulate the use of three-phase power grid section ends connected load, STATCOM main circuit reactance in parallel by connecting to the grid
The presentation is focused on different applications of the same power converter topology, the half-bridge voltage source inverter, considered both in its single- and three-phase implementation....
Mitigation of Power Quality Issues Due to High Penetration of Renewable Energy Sources in Electric Grid Systems Using Three-Phase APF/STATCOM Technologies: A Review
This project is essentially a simulation of hydroelectric dam created on MATLAB ,to predict the electricity supplied by hydroelectric dam by forecasting the next hour electricity demand based on three...
Ultra-Low Voltage and Ultra-Low Power Consumption Nonvolatile Operation of a Three-Terminal Atomic Switch
Advances in optical technology and computing power are bringing life-like 3DTV closer, with potential applications not only in entertainment, but also in education, scientific research, industry, ...
A real synchrophasor set composing of three different types of disturbance events from the Frequency Monitoring Network (FNET) is used. An image embedding technique called Gramian Angular Field is ...
Three.js is the most popular JavaScript library for displaying 3D content on the web, giving you the power to display incredible models, games, music videos, and scientific/data visualizations in your...
His three-book series on Power Electronics focuses on three essential topics in the power sequence based on applications relevant to this age of sustainable energy such as wind turbines and hybrid ...
power device that consists of three components: a sensing ... algorithm for nodes localization in three-dimensional WSN. Since MDS-MAP is one of the algorithms that produce ... Finally, we conclude ...
Three.js is the most popular JavaScript library for displaying 3D content on the web, giving you the power to display incredible models, games, music videos, and scientific/data visualizations in your...
讲解了3相电机的控制方法。... The electric drive does not only consist of the electric machine, but according to modern understanding also of power electronics, sensors and multi-level controls units.
The book also covers advanced topics of parallelism, pipelining, power and energy, and performance. A hands-on lab is also included. The second edition contains three new chapters as well as changes ...
From an ideal 2400-Volt DC source a 2-MVA three-phase 3-level inverter delivers power to a 25-kV distribution system. A sine filter is used on the secondary side of the distribution transformer in ...
Improved Performance of Three Phase Motor with High Power Quality Based on Dual Boost Converter
Run DC power flows and calculate network response of three tie lines for any additional MW transfer from Area to area