-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
๐ฌย ๋ฌธ์
https://app.codility.com/programmers/trainings/5/parity_degree/
๐ฌย Idea
- 2์ ๊ฑฐ๋ญ์ ๊ณฑ์ 0๋ถํฐ ์์ํ ์ ์์์ ์ ์ํ์. 2^0 = 1
- 0๋ถํฐ N๊น์ง ๋๋ฉด์ 2์ ๊ฑฐ๋ญ์ ๊ณฑ์ ๊ตฌํ๊ณ , ํด๋น ๊ฐ์ด N๋ณด๋ค ํฌ๋ค๋ฉด ๋ฐ๋ณต๋ฌธ์ ํ์ถํ๋ค. ๊ทธ๋ ์ง ์๊ณ N์ด ํด๋น 2์ ๊ฑฐ๋ญ์ ๊ณฑ์ผ๋ก ๋๋ ์ง๋ค๋ฉด maxPow๋ฅผ ๊ฐฑ์ ํ๋ค.
๐ฌย ํ์ด
public func solution1(N : Int) -> Int {
var maxPow = 0
for i in 0..<N {
let p = Int(pow(2.0, Double(i)))
if N < p { break }
if N % p == 0 {
maxPow = max(i, maxPow)
}
}
return maxPow
}
**์์์๊ฐ**
:
ํ๊ฐํ
: https://app.codility.com/demo/results/trainingU3BJ6B-8FZ/