-
92. Number of 1 BitsProblem Solving 2023. 1. 19. 04:39728x90
https://leetcode.com/problems/number-of-1-bits/description/
Number of 1 Bits - LeetCode
Number of 1 Bits - Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight [http://en.wikipedia.org/wiki/Hamming_weight]). Note: * Note that in some languages, such as Java, there is no un
leetcode.com
2진수로 변환한 후 자릿수 1이 몇 개인지 세는 문제
class Solution: def hammingWeight(self, n: int) -> int: number = str(bin(n)) count = 0 for i in number: if i == '1': count = count + 1 return count
int(n, 2)와 bin(n)을 헷갈렸다
'Problem Solving' 카테고리의 다른 글
94. Merge Sorted Array (1) 2023.01.19 93. 크로아티아 알파벳 (1) 2023.01.19 91. Two Sum II - Input Array Is Sorted (0) 2023.01.19 90. Valid Parentheses (0) 2023.01.19 89. Unique Morse Code Words (0) 2023.01.19