From b88e3e0f742dcec502723fc56203076ef4938437 Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Mon, 20 May 2024 07:52:28 +0100 Subject: [PATCH 1/2] Swift Implementation for LCOF 10-I --- .../README.md" | 17 +++++++++++++++++ .../Solution.swift" | 14 ++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 "lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.swift" diff --git "a/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" index 7d38e46f39ac0..c917542d2102e 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" @@ -177,6 +177,23 @@ public class Solution { } ``` +```swift +class Solution { + func fib(_ n: Int) -> Int { + var a = 0 + var b = 1 + var count = n + while count > 0 { + let c = (a + b) % 1000000007 + a = b + b = c + count -= 1 + } + return a + } +} +``` + diff --git "a/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.swift" "b/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.swift" new file mode 100644 index 0000000000000..29af382ba2350 --- /dev/null +++ "b/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/Solution.swift" @@ -0,0 +1,14 @@ +class Solution { + func fib(_ n: Int) -> Int { + var a = 0 + var b = 1 + var count = n + while count > 0 { + let c = (a + b) % 1000000007 + a = b + b = c + count -= 1 + } + return a + } +} \ No newline at end of file From fd747e488bbf80252f2c1c187e5b3aa8dbc8d11e Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Mon, 20 May 2024 08:58:03 +0100 Subject: [PATCH 2/2] code update --- .../README.md" | 2 ++ 1 file changed, 2 insertions(+) diff --git "a/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" index c917542d2102e..d60943d259517 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23010- I. \346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227/README.md" @@ -177,6 +177,8 @@ public class Solution { } ``` +#### Swift + ```swift class Solution { func fib(_ n: Int) -> Int {