From 3cc60d04312dfab6b563b8308a88a155c6a3a362 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Mon, 13 Jun 2022 19:19:48 +0100 Subject: [PATCH] triangle --- triangle/sol.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 triangle/sol.rs diff --git a/triangle/sol.rs b/triangle/sol.rs new file mode 100644 index 0000000..0fba4b9 --- /dev/null +++ b/triangle/sol.rs @@ -0,0 +1,10 @@ +impl Solution { + pub fn minimum_total(mut triangle: Vec>) -> i32 { + for row in (0..triangle.len() - 1).rev() { + for idx in 0..row + 1 { + triangle[row][idx] += triangle[row + 1][idx].min(triangle[row + 1][idx + 1]); + } + } + triangle[0][0] + } +} \ No newline at end of file