https://leetcode.com/problems/number-of-1-bits/
public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
String s = Integer.toBinaryString(n);
return (s.replace("0","")).length();
}
}
'알고리즘 > 코딩테스트' 카테고리의 다른 글
[leetcode] Product of Array Except Self (0) | 2022.04.24 |
---|---|
[leetcode] Maximum Product Subarray (0) | 2022.04.22 |
[leetcode] three sum (0) | 2022.04.13 |
[SQL] leetCode Department Top Three Salaries (0) | 2022.03.24 |
[SQL] leetcode Second Highest Salary (0) | 2022.03.22 |