Skip to content

Commit 526b013

Browse files
committed
feat: add solutions to lcp problem: No.01
1 parent 6de67cb commit 526b013

File tree

7 files changed

+69
-5
lines changed

7 files changed

+69
-5
lines changed

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121
## 站点
2222

2323
- Netlify: https://lc.netlify.app
24-
- ~~Gitee Pages: https://doocs.gitee.io/leetcode~~
24+
- Gitee Pages: https://doocs.gitee.io/leetcode
2525
- GitHub Pages: https://doocs.github.io/leetcode
2626

27-
注:Gitee Pages 站点被 Gitee 官方误判为“包含违禁违规内容”,惨遭下线。
28-
2927
## LeetCode 全解
3028

3129
- [LeetCode](./solution/README.md)

README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Complete solutions to [LeetCode](https://leetcode.com/problemset/all/), [LCOF](h
2121
## Sites
2222

2323
- Netlify: https://lc.netlify.app
24+
- Gitee Pages: https://doocs.gitee.io/leetcode
2425
- GitHub Pages: https://doocs.github.io/leetcode
2526

2627
## Solutions

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

+38-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<li><code>answer</code> 的元素取值为 <code>{1, 2, 3}</code> 之一。</li>
3636
</ol>
3737

38-
3938
## 解法
4039

4140
<!-- 这里可写通用的实现逻辑 -->
@@ -47,15 +46,52 @@
4746
<!-- 这里可写当前语言的特殊实现逻辑 -->
4847

4948
```python
50-
49+
class Solution:
50+
def game(self, guess: List[int], answer: List[int]) -> int:
51+
return sum(1 for i in range(3) if guess[i] == answer[i])
5152
```
5253

5354
### **Java**
5455

5556
<!-- 这里可写当前语言的特殊实现逻辑 -->
5657

5758
```java
59+
class Solution {
60+
public int game(int[] guess, int[] answer) {
61+
int times = 0;
62+
for (int i = 0; i < 3; ++i) {
63+
times += (guess[i] == answer[i] ? 1 : 0);
64+
}
65+
return times;
66+
}
67+
}
68+
```
69+
70+
### **C++**
71+
72+
```cpp
73+
class Solution {
74+
public:
75+
int game(vector<int>& guess, vector<int>& answer) {
76+
int times = 0;
77+
for (int i = 0; i < 3; ++i) times += guess[i] == answer[i];
78+
return times;
79+
}
80+
};
81+
```
5882
83+
### **Go**
84+
85+
```go
86+
func game(guess []int, answer []int) int {
87+
times := 0
88+
for i := 0; i < 3; i++ {
89+
if guess[i] == answer[i] {
90+
times++
91+
}
92+
}
93+
return times
94+
}
5995
```
6096

6197
### **...**

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

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution {
2+
public:
3+
int game(vector<int>& guess, vector<int>& answer) {
4+
int times = 0;
5+
for (int i = 0; i < 3; ++i) times += guess[i] == answer[i];
6+
return times;
7+
}
8+
};

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

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
func game(guess []int, answer []int) int {
2+
times := 0
3+
for i := 0; i < 3; i++ {
4+
if guess[i] == answer[i] {
5+
times++
6+
}
7+
}
8+
return times
9+
}

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

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution {
2+
public int game(int[] guess, int[] answer) {
3+
int times = 0;
4+
for (int i = 0; i < 3; ++i) {
5+
times += (guess[i] == answer[i] ? 1 : 0);
6+
}
7+
return times;
8+
}
9+
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def game(self, guess: List[int], answer: List[int]) -> int:
3+
return sum(1 for i in range(3) if guess[i] == answer[i])

0 commit comments

Comments
 (0)