diff --git "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/README.md" index abb3d16bae1f6..a5567719f731d 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/README.md" @@ -147,6 +147,18 @@ public class Solution { } ``` +#### Swift + +```swift +class Solution { + func sumNums(_ n: Int) -> Int { + var s = n + let _ = n > 0 && { s += sumNums(n - 1); return true }() + return s + } +} +``` + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.swift" "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.swift" new file mode 100644 index 0000000000000..b4e68eb75c3b3 --- /dev/null +++ "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.swift" @@ -0,0 +1,7 @@ +class Solution { + func sumNums(_ n: Int) -> Int { + var s = n + let _ = n > 0 && { s += sumNums(n - 1); return true }() + return s + } +} \ No newline at end of file