Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dbed118

Browse files
feat: add swift implementation to lcp problem: No.01 (doocs#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‎

Lines changed: 16 additions & 0 deletions
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‎

Lines changed: 11 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /