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 |
Tags
- 1253번
- Unreal
- FBX
- 비재귀셰그먼트
- 1967번
- OS
- 민겸수
- 언리얼 플러그인
- 백준 1253번
- command not found
- SQL
- 백준
- 트랜잭션 관리
- 언리얼 커스텀 플러그인
- 의미와 무의미의 경계에서
- 5639
- 오손데이터읽기
- oracle
- Security
- 1759번
- 실습
- 셰그먼트트리
- Linux
- UActor
- hackerank
- UnrealMP
- 2단계로킹
- objtofbx
- C++
- 데이터베이스 배움터
Archives
- Today
- Total
fatalite
Flipping Bits 본문
Function Description
Complete the flippingBits function in the editor below.
flippingBits has the following parameter(s):
- int n: an integer
Solution Code
long flippingBits(long n) {
//32bit
bool a[32];
for(int i = 31; i >= 0; i--){
if(pow(2,i) <= n){
a[31-i] = 0;
//std::cout << a[31-i];
n = n - pow(2,i);
}else{
a[31-i] = 1;
//std::cout << a[31-i];
}
}
long results = 0;
for(int i = 31; i >= 0; i--){
if(a[31-i] == 1){
results = results + pow(2,i);
}
}
return results;
}
'코딩 인터뷰 > C++' 카테고리의 다른 글
Subarray Division 2 (0) | 2023.02.03 |
---|---|
Permuting Two Arrays (0) | 2023.01.26 |
Mars Exploration (0) | 2023.01.18 |
Counting Valleys (0) | 2023.01.17 |
Diagonal Difference (0) | 2023.01.13 |