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:
File size: 1,097 Bytes
75cb225 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | impl Solution {
pub fn advantages(s: Vec<i64>) -> Vec<i64> {
let n = s.len();
let mut max1: i64 = s[0];
let mut idx1: usize = 0;
let mut max2: i64 = s[1];
let mut idx2: usize = 1;
if max2 > max1 {
let tv = max1;
let ti = idx1;
max1 = max2;
idx1 = idx2;
max2 = tv;
idx2 = ti;
}
let mut t: usize = 2;
while t < n {
if s[t] > max1 {
max2 = max1;
idx2 = idx1;
max1 = s[t];
idx1 = t;
} else if s[t] > max2 {
max2 = s[t];
idx2 = t;
}
t = t + 1;
}
let mut result: Vec<i64> = Vec::with_capacity(n);
let mut i: usize = 0;
while i < n {
let best: i64;
if i == idx1 {
best = max2;
} else {
best = max1;
}
result.push(s[i] - best);
i = i + 1;
}
result
}
}
|