diff --git "a/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/README.md" "b/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/README.md" index 27eaab2822b7b..4ddf53357c988 100644 --- "a/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/README.md" +++ "b/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/README.md" @@ -155,6 +155,22 @@ int game(int* guess, int guessSize, int* answer, int answerSize) { } ``` +#### Swift + +```swift +class Solution { + func game(_ guess: [Int], _ answer: [Int]) -> Int { + var correctGuesses = 0 + for i in 0..<3 { + if guess[i] == answer[i] { + correctGuesses += 1 + } + } + return correctGuesses + } +} +``` + diff --git "a/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/Solution.swift" "b/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/Solution.swift" new file mode 100644 index 0000000000000..23f55f3b0e31d --- /dev/null +++ "b/lcp/LCP 01. \347\214\234\346\225\260\345\255\227/Solution.swift" @@ -0,0 +1,11 @@ +class Solution { + func game(_ guess: [Int], _ answer: [Int]) -> Int { + var correctGuesses = 0 + for i in 0..<3 { + if guess[i] == answer[i] { + correctGuesses += 1 + } + } + return correctGuesses + } +}