init6
/
์๊ณ ๋ฆฌ์ฆ DB
/
power of two
Search
Duplicate
Share
๐
power of two
์ฃผ์ฐจ
๋ฌธ์ ๋ฒํธ
231
์ธ์ด
Swift
ํฐ์ด
Easy
์ ํ
์ํ
nj_Blog
nj_์ํ
์ดํด๋
100%
ํ์ด
์ฌ๋
์ดํด๋ 2
13 more properties
Power of Two - LeetCode
Given an integer n, return true if it is a power of two. Otherwise, return false . An integer n is a power of two, if there exists an integer x such that . Example 1: Example 2: Example 3: Example 4: Example 5: Constraints: Follow up: Could you solve it without loops/recursion?
๋ฌธ์ ์ ๊ทผ
๋์ณค๋ ๋ถ๋ถ
์ฝ๋
13.5 MB
0 ms
class
Solution
{
func
isPowerOfTwo
(
_ n
:
Int
)
->
Bool
{
var temp
=
1
while
(
temp
<
n
)
{
temp
*=
2
}
return
temp
==
n
//n์ ๊น์ง temp์ 2๋ฅผ ๊ณฑํ๊ณ true ํน์ false ๋ฐํ
}
}
C++
๋ณต์ฌ