From 28f6085d8be491a8b416bd55c3061130afe82a4c Mon Sep 17 00:00:00 2001 From: Lanre Adedara Date: Mon, 4 Nov 2024 08:36:37 +0100 Subject: [PATCH] feat: add swift implementation to lcp problem: No.01 --- .../README.md" | 16 ++++++++++++++++ .../Solution.swift" | 11 +++++++++++ 2 files changed, 27 insertions(+) create mode 100644 "lcp/LCP 01. \347\214\234\346\225\260\345\255\227/Solution.swift" 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 + } +}