diff --git a/lcci/17.16.The Masseuse/README.md b/lcci/17.16.The Masseuse/README.md index 196dd65e92c46..2ac6e20444ef1 100644 --- a/lcci/17.16.The Masseuse/README.md +++ b/lcci/17.16.The Masseuse/README.md @@ -119,6 +119,24 @@ function massage(nums: number[]): number { } ``` +```swift +class Solution { + func massage(_ nums: [Int]) -> Int { + var f = 0 + var g = 0 + + for x in nums { + let ff = g + x + let gg = max(f, g) + f = ff + g = gg + } + + return max(f, g) + } +} +``` + diff --git a/lcci/17.16.The Masseuse/README_EN.md b/lcci/17.16.The Masseuse/README_EN.md index 63b5510be2d38..76ffd8b9e0d01 100644 --- a/lcci/17.16.The Masseuse/README_EN.md +++ b/lcci/17.16.The Masseuse/README_EN.md @@ -116,6 +116,24 @@ function massage(nums: number[]): number { } ``` +```swift +class Solution { + func massage(_ nums: [Int]) -> Int { + var f = 0 + var g = 0 + + for x in nums { + let ff = g + x + let gg = max(f, g) + f = ff + g = gg + } + + return max(f, g) + } +} +``` + diff --git a/lcci/17.16.The Masseuse/Solution.swift b/lcci/17.16.The Masseuse/Solution.swift new file mode 100644 index 0000000000000..f4c9aef040017 --- /dev/null +++ b/lcci/17.16.The Masseuse/Solution.swift @@ -0,0 +1,15 @@ +class Solution { + func massage(_ nums: [Int]) -> Int { + var f = 0 + var g = 0 + + for x in nums { + let ff = g + x + let gg = max(f, g) + f = ff + g = gg + } + + return max(f, g) + } +} \ No newline at end of file