Power of Two - LeetCode

๋ฌธ์ œ์ ‘๊ทผ๐Ÿค”


๋†“์ณค๋˜ ๋ถ€๋ถ„๐Ÿ˜…


์ฝ”๋“œ๐Ÿ˜


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 ๋ฐ˜ํ™˜
    }
}