Compare commits

...

2 Commits

6 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "minimum_number_of_operations_to_move_all_balls_to_each_box"
version = "0.1.0"

View File

@ -0,0 +1,6 @@
[package]
name = "minimum_number_of_operations_to_move_all_balls_to_each_box"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@ -0,0 +1,33 @@
pub struct Solution;
impl Solution {
pub fn min_operations(boxes: String) -> Vec<i32> {
let boxes: Vec<i32> = boxes.chars().map(|c| c as i32 - 48).collect();
let mut balls_counted_from_left = vec![0; boxes.len()];
for i in 1..boxes.len() {
balls_counted_from_left[i] = balls_counted_from_left[i - 1] + boxes[i - 1];
}
let mut balls_counted_from_right = vec![0; boxes.len()];
for i in (0..(boxes.len() - 1)).rev() {
balls_counted_from_right[i] = balls_counted_from_right[i + 1] + boxes[i + 1];
}
let mut steps_moving_to_right = vec![0; boxes.len()];
for i in 1..boxes.len() {
steps_moving_to_right[i] = steps_moving_to_right[i - 1] + balls_counted_from_left[i];
}
let mut steps_moving_to_left = vec![0; boxes.len()];
for i in (0..(boxes.len() - 1)).rev() {
steps_moving_to_left[i] = steps_moving_to_left[i + 1] + balls_counted_from_right[i];
}
steps_moving_to_left
.iter()
.zip(steps_moving_to_right.iter())
.map(|(&l, &r)| l + r)
.collect()
}
}

7
2469_convert_the_temperature/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "convert_the_temperature"
version = "0.1.0"

View File

@ -0,0 +1,6 @@
[package]
name = "convert_the_temperature"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@ -0,0 +1,7 @@
pub struct Solution;
impl Solution {
pub fn convert_temperature(celsius: f64) -> Vec<f64> {
vec![celsius + 273.15, celsius * 1.8 + 32.0]
}
}