Skip to content

Commit bb01264

Browse files
authored
feat: add swift implementation to lcci problem: No.17.16 (doocs#2803)
1 parent 726d0be commit bb01264

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

lcci/17.16.The Masseuse/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,24 @@ function massage(nums: number[]): number {
119119
}
120120
```
121121

122+
```swift
123+
class Solution {
124+
func massage(_ nums: [Int]) -> Int {
125+
var f = 0
126+
var g = 0
127+
128+
for x in nums {
129+
let ff = g + x
130+
let gg = max(f, g)
131+
f = ff
132+
g = gg
133+
}
134+
135+
return max(f, g)
136+
}
137+
}
138+
```
139+
122140
<!-- tabs:end -->
123141

124142
<!-- end -->

lcci/17.16.The Masseuse/README_EN.md

+18
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ function massage(nums: number[]): number {
116116
}
117117
```
118118

119+
```swift
120+
class Solution {
121+
func massage(_ nums: [Int]) -> Int {
122+
var f = 0
123+
var g = 0
124+
125+
for x in nums {
126+
let ff = g + x
127+
let gg = max(f, g)
128+
f = ff
129+
g = gg
130+
}
131+
132+
return max(f, g)
133+
}
134+
}
135+
```
136+
119137
<!-- tabs:end -->
120138

121139
<!-- end -->
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
func massage(_ nums: [Int]) -> Int {
3+
var f = 0
4+
var g = 0
5+
6+
for x in nums {
7+
let ff = g + x
8+
let gg = max(f, g)
9+
f = ff
10+
g = gg
11+
}
12+
13+
return max(f, g)
14+
}
15+
}

0 commit comments

Comments
 (0)