20240912 finished.
This commit is contained in:
parent
d249f777dd
commit
e49fe8ee09
16
README.md
16
README.md
|
@ -1,5 +1,17 @@
|
|||
# LeetCode
|
||||
|
||||
运行`cargo run`来初始化题目的模板文件。
|
||||
使用Rust完成LeetCode上的题目。
|
||||
|
||||
运行`cargo test test_{id}`来运行指定题目的测试。
|
||||
## 使用方法
|
||||
|
||||
```shell
|
||||
just pull <id>
|
||||
```
|
||||
|
||||
获得指定`<id>`的题目。
|
||||
|
||||
```shell
|
||||
just commit
|
||||
```
|
||||
|
||||
提交目前完成的题目,提交信息的格式为`YYYYMMdd finished.`。
|
||||
|
|
5
justfile
5
justfile
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/env just --justfile
|
||||
|
||||
build:
|
||||
update:
|
||||
git pull
|
||||
|
||||
build: update
|
||||
cargo build --release
|
||||
|
||||
test:
|
||||
|
|
|
@ -232,4 +232,5 @@ mod p3177_find_the_maximum_length_of_a_good_subsequence_ii;
|
|||
mod p977_squares_of_a_sorted_array;
|
||||
mod p2181_merge_nodes_in_between_zeros;
|
||||
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;
|
|
@ -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]));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user