Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add swift implementation to lcci problem: No.17.16 #2803

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lcci/17.16.The Masseuse/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
```

<!-- tabs:end -->

<!-- end -->
18 changes: 18 additions & 0 deletions lcci/17.16.The Masseuse/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
```

<!-- tabs:end -->

<!-- end -->
15 changes: 15 additions & 0 deletions lcci/17.16.The Masseuse/Solution.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading