Compare commits
2 Commits
610d05ddb2
...
d4b56a88fd
Author | SHA1 | Date | |
---|---|---|---|
d4b56a88fd | |||
7848468524 |
7
1769_minimum_number_of_operations_to_move_all_balls_to_each_box/Cargo.lock
generated
Normal file
7
1769_minimum_number_of_operations_to_move_all_balls_to_each_box/Cargo.lock
generated
Normal 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"
|
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "minimum_number_of_operations_to_move_all_balls_to_each_box"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
@ -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
7
2469_convert_the_temperature/Cargo.lock
generated
Normal 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"
|
6
2469_convert_the_temperature/Cargo.toml
Normal file
6
2469_convert_the_temperature/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "convert_the_temperature"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
7
2469_convert_the_temperature/src/lib.rs
Normal file
7
2469_convert_the_temperature/src/lib.rs
Normal 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]
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user