Skip to content

Commit a1a0d65

Browse files
committed
feat: add typescript solution to lc problem: No.2260
No.2260.Minimum Consecutive Cards to Pick Up
1 parent 1e4fd7f commit a1a0d65

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

solution/2200-2299/2260.Minimum Consecutive Cards to Pick Up/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,20 @@ func min(a, b int) int {
124124
### **TypeScript**
125125

126126
```ts
127-
127+
function minimumCardPickup(cards: number[]): number {
128+
const n = cards.length;
129+
let hashMap = new Map<number, number>();
130+
const max = Number.MAX_SAFE_INTEGER;
131+
let ans = max;
132+
for (let i = 0; i < n; i++) {
133+
let num = cards[i];
134+
if (hashMap.has(num)) {
135+
ans = Math.min(i - hashMap.get(num) + 1, ans);
136+
}
137+
hashMap.set(num, i);
138+
}
139+
return ans == max ? -1 : ans;
140+
};
128141
```
129142

130143
### **...**

solution/2200-2299/2260.Minimum Consecutive Cards to Pick Up/README_EN.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,20 @@ func min(a, b int) int {
118118
### **TypeScript**
119119

120120
```ts
121-
121+
function minimumCardPickup(cards: number[]): number {
122+
const n = cards.length;
123+
let hashMap = new Map<number, number>();
124+
const max = Number.MAX_SAFE_INTEGER;
125+
let ans = max;
126+
for (let i = 0; i < n; i++) {
127+
let num = cards[i];
128+
if (hashMap.has(num)) {
129+
ans = Math.min(i - hashMap.get(num) + 1, ans);
130+
}
131+
hashMap.set(num, i);
132+
}
133+
return ans == max ? -1 : ans;
134+
};
122135
```
123136

124137
### **...**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function minimumCardPickup(cards: number[]): number {
2+
const n = cards.length;
3+
let hashMap = new Map<number, number>();
4+
const max = Number.MAX_SAFE_INTEGER;
5+
let ans = max;
6+
for (let i = 0; i < n; i++) {
7+
let num = cards[i];
8+
if (hashMap.has(num)) {
9+
ans = Math.min(i - hashMap.get(num) + 1, ans);
10+
}
11+
hashMap.set(num, i);
12+
}
13+
return ans == max ? -1 : ans;
14+
};

0 commit comments

Comments
 (0)