Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- Data Structure
- Counting
- Binary Search
- Matrix
- greedy
- Method
- geometry
- 코딩테스트
- SQL
- Binary Tree
- string
- simulation
- implement
- 파이썬
- java
- 자바
- hash table
- two pointers
- dynamic programming
- bit manipulation
- Class
- Tree
- array
- 구현
- database
- 코테
- Number Theory
- sorting
- Math
- Stack
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 191. Number of 1 Bits 본문
1. Input
1) unsigned 정수 n
2. Output
1) n에 담긴 1의 개수를 int 변수에 담아 반환
3. Constraint
1) n은 길이가 32인 2진 문자열
4. Example
Input: n = 00000000000000000000000000001011
Output: 3
5. Code
1) 첫 코드(2022/07/22)
String s = Integer.toBinaryString(n);
n = 0;
for(int i=0 ; i<s.length() ; i++)
if(s.charAt(i)=='1')
n++;
return n;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 231. Power of Two (0) | 2022.10.13 |
---|---|
[LeetCode/Easy] 217. Contains Duplicate (0) | 2022.10.12 |
[LeetCode/Easy] 190. Reverse Bits (0) | 2022.10.12 |
[LeetCode/Easy] 171. Excel Sheet Column Number (0) | 2022.10.12 |
[LeetCode/Easy] 136. Single Number (0) | 2022.10.11 |