Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
ArXiv:
Tags:
competitive-programming
code-generation
specification-generation
proof-generation
verification
rust
License:
Download leetcode/lc1558/code.rs from Gax-c/VeriContest_Lite: direct link, hf CLI and curl.
- Browser
- Download file 758 Bytes
-
https://huggingface.co/datasets/Gax-c/VeriContest_Lite/resolve/main/leetcode/lc1558/code.rs
- Command line
-
hf download hf://datasets/Gax-c/VeriContest_Lite/leetcode/lc1558/code.rs
-
curl -L -o code.rs https://huggingface.co/datasets/Gax-c/VeriContest_Lite/resolve/main/leetcode/lc1558/code.rs
758 Bytes
| impl Solution { | |
| pub fn min_operations(nums: Vec<i32>) -> i32 { | |
| let mut ones: i32 = 0; | |
| let mut max_len: i32 = 0; | |
| let n = nums.len(); | |
| let mut i: usize = 0; | |
| while i < n { | |
| let mut val = nums[i]; | |
| let mut bits: i32 = 0; | |
| let mut len: i32 = 0; | |
| while val > 0 { | |
| if val % 2 == 1 { | |
| bits = bits + 1; | |
| } | |
| val = val / 2; | |
| len = len + 1; | |
| } | |
| ones = ones + bits; | |
| if len > max_len { | |
| max_len = len; | |
| } | |
| i = i + 1; | |
| } | |
| if max_len > 0 { | |
| ones + max_len - 1 | |
| } else { | |
| ones | |
| } | |
| } | |
| } | |