Skip to content

Commit 0ea57c8

Browse files
committed
feat: add c solution to lcp problems: No.01,06
- No.LCP 01. 猜数字 - No.LCP 06. 拿硬币
1 parent 2b4c581 commit 0ea57c8

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@ var game = function (guess, answer) {
111111
};
112112
```
113113

114+
### **C**
115+
116+
```c
117+
int game(int* guess, int guessSize, int* answer, int answerSize) {
118+
int res = 0;
119+
for (int i = 0; i < 3; i++) {
120+
if (guess[i] == answer[i]) {
121+
res++;
122+
}
123+
}
124+
return res;
125+
}
126+
```
127+
114128
### **...**
115129
116130
```

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int game(int* guess, int guessSize, int* answer, int answerSize) {
2+
int res = 0;
3+
for (int i = 0; i < 3; i++) {
4+
if (guess[i] == answer[i]) {
5+
res++;
6+
}
7+
}
8+
return res;
9+
}

lcp/LCP 06. 拿硬币/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,22 @@ func minCount(coins []int) int {
8888
}
8989
```
9090

91+
### **C**
92+
93+
```c
94+
int minCount(int* coins, int coinsSize) {
95+
int res = 0;
96+
for (int i = 0 ; i < coinsSize; i++) {
97+
int coin = coins[i];
98+
if (coin % 2 == 1) {
99+
res++;
100+
}
101+
res += coin / 2;
102+
}
103+
return res;
104+
}
105+
```
106+
91107
### **...**
92108
93109
```

lcp/LCP 06. 拿硬币/Solution.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
int minCount(int* coins, int coinsSize) {
2+
int res = 0;
3+
for (int i = 0 ; i < coinsSize; i++) {
4+
int coin = coins[i];
5+
if (coin % 2 == 1) {
6+
res++;
7+
}
8+
res += coin / 2;
9+
}
10+
return res;
11+
}

0 commit comments

Comments
 (0)