20240912 finished.

This commit is contained in:
jackfiled 2024-09-12 14:13:49 +08:00
parent d249f777dd
commit e49fe8ee09
4 changed files with 73 additions and 4 deletions

View File

@ -1,5 +1,17 @@
# LeetCode # LeetCode
运行`cargo run`来初始化题目的模板文件 使用Rust完成LeetCode上的题目
运行`cargo test test_{id}`来运行指定题目的测试。 ## 使用方法
```shell
just pull <id>
```
获得指定`<id>`的题目。
```shell
just commit
```
提交目前完成的题目,提交信息的格式为`YYYYMMdd finished.`。

View File

@ -1,6 +1,9 @@
#!/usr/bin/env just --justfile #!/usr/bin/env just --justfile
build: update:
git pull
build: update
cargo build --release cargo build --release
test: test:

View File

@ -233,3 +233,4 @@ mod p977_squares_of_a_sorted_array;
mod p2181_merge_nodes_in_between_zeros; mod p2181_merge_nodes_in_between_zeros;
mod p2552_count_increasing_quadruplets; mod p2552_count_increasing_quadruplets;
mod p2555_maximize_win_from_two_segments; mod p2555_maximize_win_from_two_segments;
mod p2576_find_the_maximum_number_of_marked_indices;

View File

@ -0,0 +1,53 @@
/**
* [2576] Find the Maximum Number of Marked Indices
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn max_num_of_marked_indices(nums: Vec<i32>) -> i32 {
let mut nums = nums;
nums.sort();
let n = nums.len();
let check = |k: usize| -> bool {
for i in 0..k {
if nums[i] * 2 > nums[n - k + i] {
return false;
}
}
true
};
let (mut left, mut right) = (0, n / 2);
while left < right {
let middle = (left + right + 1) / 2;
if check(middle) {
left = middle;
} else {
right = middle - 1;
}
}
(left * 2) as i32
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_2576() {
assert_eq!(2, Solution::max_num_of_marked_indices(vec![3, 5, 2, 4]));
assert_eq!(4, Solution::max_num_of_marked_indices(vec![9, 2, 5, 4]));
assert_eq!(0, Solution::max_num_of_marked_indices(vec![7, 6, 8]));
}
}