From 668057d19c58e803e9a56d081a4c8b4ed16eb2cb Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sat, 2 Mar 2024 12:57:58 +0100 Subject: [PATCH] =?UTF-8?q?rs:=20add=20=C2=AB977.=20Squares=20of=20a=20Sor?= =?UTF-8?q?ted=20Array=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- rs/squares-of-a-sorted-array.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 rs/squares-of-a-sorted-array.rs diff --git a/rs/squares-of-a-sorted-array.rs b/rs/squares-of-a-sorted-array.rs new file mode 100644 index 0000000..80622d1 --- /dev/null +++ b/rs/squares-of-a-sorted-array.rs @@ -0,0 +1,10 @@ +impl Solution { + pub fn sorted_squares(mut nums: Vec) -> Vec { + for x in &mut nums { + *x *= *x; + } + nums.sort_unstable(); + + nums + } +}