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
- dynamic programming
- hash table
- java
- 코테
- string
- Stack
- Counting
- array
- Number Theory
- greedy
- Binary Search
- 코딩테스트
- Method
- database
- sorting
- Data Structure
- geometry
- Matrix
- 구현
- 파이썬
- Math
- bit manipulation
- simulation
- implement
- Binary Tree
- Tree
- 자바
- SQL
- two pointers
- Class
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1009. Complement of Base 10 Integer 본문
1. Input
1) int 변수 n
2. Output
1) n의 2의 보수 반환
3. Constraint
1) 0 <= n < 10^9
4. Example
Input: n = 5 -> Output: 2
설명: 5는 2진수로 101 -> 보수 처리하면 010 -> 2진수 010을 10진수로 바꾸면 2
5. Code
1) 첫 코드(2022/07/27)
String s1 = Integer.toBinaryString(n);
int len = s1.length();
int output = 0;
for(int i=0 ; i<len ; i++){
if(s1.charAt(i)=='0')
output += Math.pow(2,len-1-i);
}
return output;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1078. Occurrences After Bigram (0) | 2022.12.16 |
---|---|
[LeetCode/Easy] 1051. Height Checker (0) | 2022.12.16 |
[LeetCode/Easy] 977. Squares of a Sorted Array (0) | 2022.12.16 |
[LeetCode/Easy] 961. N-Repeated Element in Size 2N Array (0) | 2022.12.16 |
[LeetCode/Easy] 283. Move Zeroes (0) | 2022.12.10 |