Skip to content

Commit dbed118

Browse files
authored
feat: add swift implementation to lcp problem: No.01 (#3714)
1 parent 3bba305 commit dbed118

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lcp/LCP 01. 猜数字/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ int game(int* guess, int guessSize, int* answer, int answerSize) {
155155
}
156156
```
157157
158+
#### Swift
159+
160+
```swift
161+
class Solution {
162+
func game(_ guess: [Int], _ answer: [Int]) -> Int {
163+
var correctGuesses = 0
164+
for i in 0..<3 {
165+
if guess[i] == answer[i] {
166+
correctGuesses += 1
167+
}
168+
}
169+
return correctGuesses
170+
}
171+
}
172+
```
173+
158174
<!-- tabs:end -->
159175

160176
<!-- solution:end -->

lcp/LCP 01. 猜数字/Solution.swift

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
func game(_ guess: [Int], _ answer: [Int]) -> Int {
3+
var correctGuesses = 0
4+
for i in 0..<3 {
5+
if guess[i] == answer[i] {
6+
correctGuesses += 1
7+
}
8+
}
9+
return correctGuesses
10+
}
11+
}

0 commit comments

Comments
 (0)