From 8db736097265d8ea4e430f00a9e9fba94391c215 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Tue, 6 May 2025 13:23:00 +0800 Subject: [PATCH] 20250506 finished. --- src/problem/mod.rs | 2 ++ .../p1920_build_array_from_permutation.rs | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/problem/p1920_build_array_from_permutation.rs diff --git a/src/problem/mod.rs b/src/problem/mod.rs index a74456e..9403c71 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -636,3 +636,5 @@ mod p1007_minimum_domino_rotations_for_equal_row; mod p1128_number_of_equivalent_domino_pairs; mod p790_domino_and_tromino_tiling; + +mod p1920_build_array_from_permutation; diff --git a/src/problem/p1920_build_array_from_permutation.rs b/src/problem/p1920_build_array_from_permutation.rs new file mode 100644 index 0000000..8032ec0 --- /dev/null +++ b/src/problem/p1920_build_array_from_permutation.rs @@ -0,0 +1,31 @@ +/** + * [1920] Build Array from Permutation + */ +pub struct Solution {} + +// submission codes start here + +impl Solution { + pub fn build_array(nums: Vec) -> Vec { + nums.iter().map(|x| nums[*x as usize]).collect() + } +} + +// submission codes end + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_1920() { + assert_eq!( + vec![0, 1, 2, 4, 5, 3], + Solution::build_array(vec![0, 2, 1, 5, 3, 4]) + ); + assert_eq!( + vec![4, 5, 0, 1, 2, 3], + Solution::build_array(vec![5, 0, 1, 2, 3, 4]) + ); + } +}