Skip to content

Commit 5f36fc7

Browse files
authoredAug 1, 2023
feat: add ts solution to lc problem: No.0822 (#1366)
1 parent 7ceaff4 commit 5f36fc7

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed
 

‎solution/0800-0899/0822.Card Flipping Game/README.md

+28-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
<pre>
2424
<strong>输入:</strong>fronts = [1,2,4,4,7], backs = [1,3,4,1,3]
25-
<strong>输出:</strong><code>2</code>
26-
<strong>解释:</strong>假设我们翻转第二张卡片,那么在正面的数变成了 <code>[1,3,4,4,7]</code> , 背面的数变成了 <code>[1,2,4,1,3]。</code>
25+
<strong>输出:</strong>2
26+
<strong>解释:</strong>假设我们翻转第二张卡片,那么在正面的数变成了 [1,3,4,4,7] , 背面的数变成了 [1,2,4,1,3]。
2727
接着我们选择第二张卡片,因为现在该卡片的背面的数是 2,2 与任意卡片上正面的数都不同,所以 2 就是我们想要的数字。</pre>
2828

2929
<p>&nbsp;</p>
@@ -146,6 +146,32 @@ func min(a, b int) int {
146146
}
147147
```
148148

149+
### **TypeScript**
150+
151+
```ts
152+
function flipgame(fronts: number[], backs: number[]): number {
153+
const s: Set<number> = new Set();
154+
const n = fronts.length;
155+
for (let i = 0; i < n; ++i) {
156+
if (fronts[i] === backs[i]) {
157+
s.add(fronts[i]);
158+
}
159+
}
160+
let ans = 9999;
161+
for (const v of fronts) {
162+
if (!s.has(v)) {
163+
ans = Math.min(ans, v);
164+
}
165+
}
166+
for (const v of backs) {
167+
if (!s.has(v)) {
168+
ans = Math.min(ans, v);
169+
}
170+
}
171+
return ans % 9999;
172+
};
173+
```
174+
149175
### **...**
150176

151177
```

‎solution/0800-0899/0822.Card Flipping Game/README_EN.md

+26
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,32 @@ func min(a, b int) int {
140140
}
141141
```
142142

143+
### **TypeScript**
144+
145+
```ts
146+
function flipgame(fronts: number[], backs: number[]): number {
147+
const s: Set<number> = new Set();
148+
const n = fronts.length;
149+
for (let i = 0; i < n; ++i) {
150+
if (fronts[i] === backs[i]) {
151+
s.add(fronts[i]);
152+
}
153+
}
154+
let ans = 9999;
155+
for (const v of fronts) {
156+
if (!s.has(v)) {
157+
ans = Math.min(ans, v);
158+
}
159+
}
160+
for (const v of backs) {
161+
if (!s.has(v)) {
162+
ans = Math.min(ans, v);
163+
}
164+
}
165+
return ans % 9999;
166+
};
167+
```
168+
143169
### **...**
144170

145171
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function flipgame(fronts: number[], backs: number[]): number {
2+
const s: Set<number> = new Set();
3+
const n = fronts.length;
4+
for (let i = 0; i < n; ++i) {
5+
if (fronts[i] === backs[i]) {
6+
s.add(fronts[i]);
7+
}
8+
}
9+
let ans = 9999;
10+
for (const v of fronts) {
11+
if (!s.has(v)) {
12+
ans = Math.min(ans, v);
13+
}
14+
}
15+
for (const v of backs) {
16+
if (!s.has(v)) {
17+
ans = Math.min(ans, v);
18+
}
19+
}
20+
return ans % 9999;
21+
};

‎solution/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
682,
2222
753,
2323
818,
24+
822,
2425
824,
2526
830,
2627
860,

0 commit comments

Comments
 (0)