We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3bca478 commit def2187Copy full SHA for def2187
lcof/面试题62. 圆圈中最后剩下的数字/README.md
@@ -161,6 +161,24 @@ public class Solution {
161
}
162
```
163
164
+#### Swift
165
+
166
+```swift
167
+class Solution {
168
+ func lastRemaining(_ n: Int, _ m: Int) -> Int {
169
+ return f(n, m)
170
+ }
171
172
+ private func f(_ n: Int, _ m: Int) -> Int {
173
+ if n == 1 {
174
+ return 0
175
176
+ let x = f(n - 1, m)
177
+ return (m + x) % n
178
179
+}
180
+```
181
182
<!-- tabs:end -->
183
184
<!-- solution:end -->
lcof/面试题62. 圆圈中最后剩下的数字/Solution.swift
@@ -0,0 +1,13 @@
1
2
3
4
5
6
7
8
9
10
11
12
13
0 commit comments