파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 8. 26. 23:45

https://leetcode.com/problems/reordered-power-of-2/

 

Reordered Power of 2 - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

비트 연산자를 활용해서 풀면 됨.

class Solution:
    def reorderedPowerOf2(self, n: int) -> bool:
        count = collections.Counter(str(n))
        return any(count == collections.Counter(str(1 << b)) for b in range(31))
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.08.28
Today's Challenge  (0) 2022.08.27
Today's Challenge  (0) 2022.08.25
Today's Challenge  (0) 2022.08.24
Today's Challenge  (0) 2022.08.23
Comments