From b1791e7259c059e805c647492d5b3c126d985eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D0=B1=D0=B0=D0=B5=D0=B2=20=D0=90?= =?UTF-8?q?=D0=B7=D0=B0=D1=82?= Date: Thu, 16 Mar 2023 12:20:24 +0300 Subject: [PATCH] Solve problem 2418 using Swift --- problems/swift/2418/Solution1.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 problems/swift/2418/Solution1.swift diff --git a/problems/swift/2418/Solution1.swift b/problems/swift/2418/Solution1.swift new file mode 100644 index 0000000..c30ae08 --- /dev/null +++ b/problems/swift/2418/Solution1.swift @@ -0,0 +1,17 @@ +class Solution { + func sortPeople(_ names: [String], _ heights: [Int]) -> [String] { + var indexHeightTuples = [(Int, Int)]() + var result = [String]() + + for (index, value) in heights.enumerated() { + indexHeightTuples.append((index, value)) + } + + indexHeightTuples.sort(by: {$0.1 > $1.1}) + + for (index, value) in indexHeightTuples { + result.append(names[index]) + } + return result + } +}