File tree Expand file tree Collapse file tree
solution/3300-3399/3314.Construct the Minimum Bitwise Array I Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -201,6 +201,29 @@ function minBitwiseArray(nums: number[]): number[] {
201201}
202202```
203203
204+ #### Rust
205+
206+ ``` rust
207+ impl Solution {
208+ pub fn min_bitwise_array (nums : Vec <i32 >) -> Vec <i32 > {
209+ let mut ans = Vec :: with_capacity (nums . len ());
210+ for x in nums {
211+ if x == 2 {
212+ ans . push (- 1 );
213+ } else {
214+ for i in 1 .. 32 {
215+ if (((x >> i ) & 1 ) ^ 1 ) == 1 {
216+ ans . push (x ^ (1 << (i - 1 )));
217+ break ;
218+ }
219+ }
220+ }
221+ }
222+ ans
223+ }
224+ }
225+ ```
226+
204227<!-- tabs: end -->
205228
206229<!-- solution: end -->
Original file line number Diff line number Diff line change @@ -195,6 +195,29 @@ function minBitwiseArray(nums: number[]): number[] {
195195}
196196```
197197
198+ #### Rust
199+
200+ ``` rust
201+ impl Solution {
202+ pub fn min_bitwise_array (nums : Vec <i32 >) -> Vec <i32 > {
203+ let mut ans = Vec :: with_capacity (nums . len ());
204+ for x in nums {
205+ if x == 2 {
206+ ans . push (- 1 );
207+ } else {
208+ for i in 1 .. 32 {
209+ if (((x >> i ) & 1 ) ^ 1 ) == 1 {
210+ ans . push (x ^ (1 << (i - 1 )));
211+ break ;
212+ }
213+ }
214+ }
215+ }
216+ ans
217+ }
218+ }
219+ ```
220+
198221<!-- tabs: end -->
199222
200223<!-- solution: end -->
Original file line number Diff line number Diff line change 1+ impl Solution {
2+ pub fn min_bitwise_array ( nums : Vec < i32 > ) -> Vec < i32 > {
3+ let mut ans = Vec :: with_capacity ( nums. len ( ) ) ;
4+ for x in nums {
5+ if x == 2 {
6+ ans. push ( -1 ) ;
7+ } else {
8+ for i in 1 ..32 {
9+ if ( ( ( x >> i) & 1 ) ^ 1 ) == 1 {
10+ ans. push ( x ^ ( 1 << ( i - 1 ) ) ) ;
11+ break ;
12+ }
13+ }
14+ }
15+ }
16+ ans
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments