Skip to content

Commit

Permalink
bitwise, leetcode pod
Browse files Browse the repository at this point in the history
  • Loading branch information
kaustubhdeokar committed Sep 11, 2024
1 parent 13ff91b commit 30bc15a
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 158 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
*.class
/out/
*.iml
./out/**
./.idea/**
/.vscode/**
out/
.vscode/
.idea/
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/misc.xml

This file was deleted.

124 changes: 0 additions & 124 deletions .idea/uiDesigner.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

Binary file removed .vscode/ipch/39c5b0228ada55e9/mmap_address.bin
Binary file not shown.
Binary file removed .vscode/ipch/39c5b0228ada55e9/selection.ipch
Binary file not shown.
Empty file added file.txt
Empty file.
11 changes: 0 additions & 11 deletions out/production/dp/dp.iml

This file was deleted.

39 changes: 39 additions & 0 deletions topics/topics/bitwise/min_bits_flip.cpp
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;
}

0 comments on commit 30bc15a

Please sign in to comment.