From daff6c3233e5aabea68f763be2f3fe29513d44c3 Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Thu, 30 May 2024 08:01:16 +0100 Subject: [PATCH] Swift implementation for LCOF 64 --- .../README.md" | 12 ++++++++++++ .../Solution.swift" | 7 +++++++ 2 files changed, 19 insertions(+) create mode 100644 "lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.swift" 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