diff --git a/26/01/3315.cpp b/26/01/3315.cpp new file mode 100644 index 0000000..6284041 --- /dev/null +++ b/26/01/3315.cpp @@ -0,0 +1,22 @@ +#include + +class Solution { +public: + std::vector minBitwiseArray(std::vector& nums) { + std::vector ans; + for(auto num:nums){ + if (num == 2) { + ans.push_back(-1); + continue; + } + int temp = num; + int t=0; + while (temp & 1) { + t++; + temp >>= 1; + } + ans.push_back(num ^ (1 << (t-1))); + } + return ans; + } +}; \ No newline at end of file diff --git a/26/01/go/3315.go b/26/01/go/3315.go new file mode 100644 index 0000000..fd2352c --- /dev/null +++ b/26/01/go/3315.go @@ -0,0 +1,19 @@ +package A + +func minBitwiseArray(nums []int) []int { + ans := make([]int, 0, len(nums)) + for _, num := range nums { + if num == 2 { + ans = append(ans, -1) + continue + } + temp := num + t := 0 + for temp&1 == 1 { + t++ + temp >>= 1 + } + ans = append(ans, num^(1<<(t-1))) + } + return ans +}