From 9bebfc43ba2c24240e735ed49af389260a3129e8 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sat, 1 Jun 2024 23:46:10 +0200 Subject: [PATCH] =?UTF-8?q?swift:=20add=20=C2=AB1732.=20Find=20the=20Highe?= =?UTF-8?q?st=20Altitude=C2=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matej Focko --- swift/find-the-highest-altitude.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 swift/find-the-highest-altitude.swift diff --git a/swift/find-the-highest-altitude.swift b/swift/find-the-highest-altitude.swift new file mode 100644 index 0000000..261a989 --- /dev/null +++ b/swift/find-the-highest-altitude.swift @@ -0,0 +1,13 @@ +class Solution { + func largestAltitude(_ gain: [Int]) -> Int { + var m = 0 + + var alt = 0 + for d in gain { + alt += d + m = max(m, alt) + } + + return m + } +}