Skip to content

Commit a644a08

Browse files
authored
Added solution for 2592
1 parent 512b19b commit a644a08

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Diff for: 02592. Maximize Greatness of an Array.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
impl Solution {
2+
// Sort the nums vector. Then create 2 markers that start from end, one for perm and one for nums. If perm is greater than nums, then move both markers, else only move nums marker. The result is the number of combinations where perm is greater than nums
3+
pub fn maximize_greatness(mut nums: Vec<i32>) -> i32 {
4+
let mut result = 0;
5+
nums.sort();
6+
let mut i = nums.len() - 1;
7+
let mut j = nums.len() - 1;
8+
9+
loop {
10+
if i != j {
11+
if nums[i] > nums[j] {
12+
result += 1;
13+
i -= 1;
14+
}
15+
}
16+
if j == 0 {
17+
break;
18+
}
19+
j -= 1;
20+
}
21+
return result;
22+
}
23+
}

0 commit comments

Comments
 (0)