Skip to content

Commit a9bd8a4

Browse files
authored
feat: add swift implementation to lcof problem: No.64 (doocs#2959)
1 parent 3a84536 commit a9bd8a4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lcof/面试题64. 求1+2+…+n/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ public class Solution {
147147
}
148148
```
149149

150+
#### Swift
151+
152+
```swift
153+
class Solution {
154+
func sumNums(_ n: Int) -> Int {
155+
var s = n
156+
let _ = n > 0 && { s += sumNums(n - 1); return true }()
157+
return s
158+
}
159+
}
160+
```
161+
150162
<!-- tabs:end -->
151163

152164
<!-- solution:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution {
2+
func sumNums(_ n: Int) -> Int {
3+
var s = n
4+
let _ = n > 0 && { s += sumNums(n - 1); return true }()
5+
return s
6+
}
7+
}

0 commit comments

Comments
 (0)