diff --git "a/lcp/LCP 22. \351\273\221\347\231\275\346\226\271\346\240\274\347\224\273/README.md" "b/lcp/LCP 22. \351\273\221\347\231\275\346\226\271\346\240\274\347\224\273/README.md" index 92ac9d2fb7720..683c73c8e8a73 100644 --- "a/lcp/LCP 22. \351\273\221\347\231\275\346\226\271\346\240\274\347\224\273/README.md" +++ "b/lcp/LCP 22. \351\273\221\347\231\275\346\226\271\346\240\274\347\224\273/README.md" @@ -195,6 +195,41 @@ function paintingPlan(n: number, k: number): number { } ``` +#### Swift + +```swift +class Solution { + func paintingPlan(_ n: Int, _ k: Int) -> Int { + if k == 0 || k == n * n { + return 1 + } + + func combination(_ n: Int, _ r: Int) -> Int { + guard r <= n else { return 0 } + if r == 0 || r == n { return 1 } + var result = 1 + for i in 0.. diff --git "a/lcp/LCP 22. \351\273\221\347\231\275\346\226\271\346\240\274\347\224\273/Solution.swift" "b/lcp/LCP 22. \351\273\221\347\231\275\346\226\271\346\240\274\347\224\273/Solution.swift" new file mode 100644 index 0000000000000..cce487d748515 --- /dev/null +++ "b/lcp/LCP 22. \351\273\221\347\231\275\346\226\271\346\240\274\347\224\273/Solution.swift" @@ -0,0 +1,30 @@ +class Solution { + func paintingPlan(_ n: Int, _ k: Int) -> Int { + if k == 0 || k == n * n { + return 1 + } + + func combination(_ n: Int, _ r: Int) -> Int { + guard r <= n else { return 0 } + if r == 0 || r == n { return 1 } + var result = 1 + for i in 0..