파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 5. 26. 23:45

https://leetcode.com/problems/number-of-1-bits/

 

Number of 1 Bits - 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

오랫만에 매우 단순한 문제.
그냥 2진수로 바꾼다음에 1이 몇개인지 세면 된다.

class Solution:
    def hammingWeight(self, n: int) -> int:
        return str(bin(n))[2:].count('1')
반응형

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

Today's Challenge  (0) 2022.05.28
Today's Challenge  (0) 2022.05.27
Today's Challenge  (0) 2022.05.25
Today's Challenge  (0) 2022.05.24
Today's Challenge  (0) 2022.05.23
Comments