From 9ccfb288198e95c3226c5172d2cce29c24e8fd0e Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Tue, 7 May 2024 07:13:56 +0100 Subject: [PATCH] Swift Implementation for LCCI 16.10 --- lcci/16.10.Living People/README.md | 29 +++++++++++++++++++++++++ lcci/16.10.Living People/README_EN.md | 29 +++++++++++++++++++++++++ lcci/16.10.Living People/Solution.swift | 26 ++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 lcci/16.10.Living People/Solution.swift diff --git a/lcci/16.10.Living People/README.md b/lcci/16.10.Living People/README.md index 5f1f54f3efeed..dc4ea2e276747 100644 --- a/lcci/16.10.Living People/README.md +++ b/lcci/16.10.Living People/README.md @@ -173,6 +173,35 @@ impl Solution { } ``` +```swift +class Solution { + func maxAliveYear(_ birth: [Int], _ death: [Int]) -> Int { + let base = 1900 + var delta = Array(repeating: 0, count: 102) // Array to hold the changes + + for i in 0.. maxAlive { + maxAlive = currentAlive + maxYear = year + base + } + } + + return maxYear + } +} +``` + diff --git a/lcci/16.10.Living People/README_EN.md b/lcci/16.10.Living People/README_EN.md index f94d95e3d56e4..3805f09aa7be1 100644 --- a/lcci/16.10.Living People/README_EN.md +++ b/lcci/16.10.Living People/README_EN.md @@ -181,6 +181,35 @@ impl Solution { } ``` +```swift +class Solution { + func maxAliveYear(_ birth: [Int], _ death: [Int]) -> Int { + let base = 1900 + var delta = Array(repeating: 0, count: 102) // Array to hold the changes + + for i in 0.. maxAlive { + maxAlive = currentAlive + maxYear = year + base + } + } + + return maxYear + } +} +``` + diff --git a/lcci/16.10.Living People/Solution.swift b/lcci/16.10.Living People/Solution.swift new file mode 100644 index 0000000000000..bdb0884d10111 --- /dev/null +++ b/lcci/16.10.Living People/Solution.swift @@ -0,0 +1,26 @@ +class Solution { + func maxAliveYear(_ birth: [Int], _ death: [Int]) -> Int { + let base = 1900 + var delta = Array(repeating: 0, count: 102) // Array to hold the changes + + for i in 0.. maxAlive { + maxAlive = currentAlive + maxYear = year + base + } + } + + return maxYear + } +} \ No newline at end of file