Compare commits

...

3 Commits

Author SHA1 Message Date
li-chx 67d79e3553 757. 设置交集大小至少为2 2025-11-20 21:57:12 +08:00
li-chx 30e2df43c4 2589. 完成所有任务的最少时间 2025-11-20 21:55:57 +08:00
li-chx 8c281d865f 3234. 统计 1 显著的字符串的数量 2025-11-20 16:41:31 +08:00
1 changed files with 24 additions and 10 deletions

View File

@ -1,20 +1,34 @@
use std::collections::{HashSet};
mod arr;
mod list;
struct Solution;
impl Solution {
pub fn find_final_value(nums: Vec<i32>, original: i32) -> i32 {
let mut original = original;
let set = nums.into_iter().collect::<HashSet<i32>>();
while set.contains(&original) {
original *= 2;
pub fn intersection_size_two(intervals: Vec<Vec<i32>>) -> i32 {
let mut tasks = intervals;
tasks.sort_by_key(|task| task[1]);
let mut stack:Vec<Vec<i32>> = Vec::new();
stack.push(vec![-2,-2,0]);
for task in tasks.iter() {
let start = task[0];
let end = task[1];
let mut d = 2;
let pos = stack.partition_point(|x| x[0] < start) - 1;
d -= stack[stack.len() - 1][2] - stack[pos][2];
if start <= stack[pos][1] {
d -= stack[pos][1] - start + 1;
}
original
if d <= 0{
continue;
}
while end - stack[stack.len() - 1][1] <= d {
let end = stack.pop().unwrap();
d += end[1] - end[0] + 1;
}
stack.push(vec![end - d + 1, end,stack[stack.len() - 1][2] + d]);
}
stack[stack.len() - 1][2]
}
}
fn main() {
let result = Solution::find_final_value(vec![5,3,6,1,12],3);
let result = Solution::intersection_size_two(arr::make_matrix("[[1,3],[3,7],[8,9]]"));
println!("{:?}", result);
}