mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-02-27 11:58:39 +08:00
routine
This commit is contained in:
22
26/01/3315.cpp
Normal file
22
26/01/3315.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
std::vector<int> minBitwiseArray(std::vector<int>& nums) {
|
||||||
|
std::vector<int> 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;
|
||||||
|
}
|
||||||
|
};
|
||||||
19
26/01/go/3315.go
Normal file
19
26/01/go/3315.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user