From 7ad765f44539d12cbb284da4ca5028a9ba880ef2 Mon Sep 17 00:00:00 2001 From: Rodolfo P A <6721075+rodoufu@users.noreply.github.com> Date: Tue, 6 Jun 2023 16:45:35 -0300 Subject: [PATCH] Create can-make-arithmetic-progression-from-sequence.rs --- ...ke-arithmetic-progression-from-sequence.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 leetCode/array/can-make-arithmetic-progression-from-sequence.rs diff --git a/leetCode/array/can-make-arithmetic-progression-from-sequence.rs b/leetCode/array/can-make-arithmetic-progression-from-sequence.rs new file mode 100644 index 0000000..9485701 --- /dev/null +++ b/leetCode/array/can-make-arithmetic-progression-from-sequence.rs @@ -0,0 +1,20 @@ +// https://leetcode.com/problems/can-make-arithmetic-progression-from-sequence/ +impl Solution { + pub fn can_make_arithmetic_progression(arr: Vec) -> bool { + if arr.len() < 2 { + return false; + } + + let mut arr = arr; + arr.sort(); + let diff = arr[1] - arr[0]; + + for i in 2..arr.len() { + if arr[i] - arr[i - 1] != diff { + return false; + } + } + + true + } +}