diff --git a/1611. Minimum One Bit Operations to Make Integers Zero b/1611. Minimum One Bit Operations to Make Integers Zero new file mode 100644 index 0000000..d1f0cf9 --- /dev/null +++ b/1611. Minimum One Bit Operations to Make Integers Zero @@ -0,0 +1,31 @@ +class Solution { +public: + int minimumOneBitOperations(int n) { + int ind=0; + vector ans; + while(n!=0){ + if((n&1)==1){ + int temp=pow(2,ind); + temp=temp*2; + temp--; + ans.push_back(temp); + } + ind++; + n=n>>1; + } + int res=0; + reverse(ans.begin(),ans.end()); + bool flag=true; + for(auto it:ans){ + if(flag){ + res+=it; + flag=false; + } + else { + res-=it; + flag=true; + } + } + return res; + } +};