From 9023c90fa2d888e18599f6094d3afa1b2f17cf7e Mon Sep 17 00:00:00 2001 From: Utkarsh Prakhar <95642114+Utkarsh048@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:32:35 +0530 Subject: [PATCH] Create Minimum One Bit Operations to Make Integers Zero.py --- Minimum One Bit Operations to Make Integers Zero.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Minimum One Bit Operations to Make Integers Zero.py diff --git a/Minimum One Bit Operations to Make Integers Zero.py b/Minimum One Bit Operations to Make Integers Zero.py new file mode 100644 index 00000000..92389abe --- /dev/null +++ b/Minimum One Bit Operations to Make Integers Zero.py @@ -0,0 +1,7 @@ +class Solution: + def minimumOneBitOperations(self, n: int) -> int: + res = 0 + while n: + res = -res - (n ^ (n - 1)) + n &= n - 1 + return abs(res)