20241121 finished.
This commit is contained in:
parent
e36031335e
commit
22ab95d5e2
|
@ -328,3 +328,5 @@ mod p661_image_smoother;
|
||||||
mod p3243_shortest_distance_after_road_addition_queries_i;
|
mod p3243_shortest_distance_after_road_addition_queries_i;
|
||||||
|
|
||||||
mod p3244_shortest_distance_after_road_addition_queries_ii;
|
mod p3244_shortest_distance_after_road_addition_queries_ii;
|
||||||
|
|
||||||
|
mod p3248_snake_in_matrix;
|
||||||
|
|
41
src/problem/p3248_snake_in_matrix.rs
Normal file
41
src/problem/p3248_snake_in_matrix.rs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/**
|
||||||
|
* [3248] Snake in Matrix
|
||||||
|
*/
|
||||||
|
pub struct Solution {}
|
||||||
|
|
||||||
|
// submission codes start here
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn final_position_of_snake(n: i32, commands: Vec<String>) -> i32 {
|
||||||
|
let (mut x, mut y) = (0, 0);
|
||||||
|
|
||||||
|
commands.iter().for_each(|str| match str.as_str() {
|
||||||
|
"UP" => x -= 1,
|
||||||
|
"DOWN" => x += 1,
|
||||||
|
"LEFT" => y -= 1,
|
||||||
|
"RIGHT" => y += 1,
|
||||||
|
_ => {}
|
||||||
|
});
|
||||||
|
|
||||||
|
x * n + y
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// submission codes end
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_3248() {
|
||||||
|
assert_eq!(
|
||||||
|
3,
|
||||||
|
Solution::final_position_of_snake(2, vec_string!("RIGHT", "DOWN"))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
1,
|
||||||
|
Solution::final_position_of_snake(3, vec_string!("DOWN", "RIGHT", "UP"))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user