Compare commits

..

No commits in common. "67d79e35531a25a47b8792e4dd32c3f652b779d1" and "742a5b6137e8063ee2687e9e1043345022f4ec5c" have entirely different histories.

1 changed files with 10 additions and 24 deletions

View File

@ -1,34 +1,20 @@
use std::collections::{HashSet};
mod arr;
mod list;
struct Solution;
impl Solution {
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;
}
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]);
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;
}
stack[stack.len() - 1][2]
original
}
}
fn main() {
let result = Solution::intersection_size_two(arr::make_matrix("[[1,3],[3,7],[8,9]]"));
let result = Solution::find_final_value(vec![5,3,6,1,12],3);
println!("{:?}", result);
}