-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13ff91b
commit 30bc15a
Showing
10 changed files
with
42 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,6 @@ | |
*.class | ||
/out/ | ||
*.iml | ||
./out/** | ||
./.idea/** | ||
/.vscode/** | ||
out/ | ||
.vscode/ | ||
.idea/ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include<cmath> | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
//leetcode problem 11sep. | ||
|
||
class Solution { | ||
public: | ||
int minBitFlips(int start, int goal) { | ||
int startCeil = start==0 ? 0: ceil(log2(start)); | ||
int goalCeil = goal ==0 ? 0: ceil(log2(goal)); | ||
int greater = startCeil>goalCeil ? startCeil:goalCeil; | ||
int mask = 1; | ||
int diff = 0; | ||
|
||
for(int i=0;i<=greater;i++){ | ||
if((mask&start)!=(mask&goal)){ | ||
diff+=1; | ||
} | ||
mask = mask<<1; | ||
} | ||
return diff; | ||
} | ||
|
||
}; | ||
|
||
|
||
int main() { | ||
Solution solution; | ||
|
||
int start = 10; | ||
int goal = 7; | ||
cout << "Minimum bit flips to convert " << start << " to " << goal << ": " << solution.minBitFlips(start, goal) << endl; | ||
|
||
start = 0; | ||
goal = 15; | ||
cout << "Minimum bit flips to convert " << start << " to " << goal << ": " << solution.minBitFlips(start, goal) << endl; | ||
|
||
return 0; | ||
} |