Skip to content

Commit 0dd886b

Browse files
committed
feat: add typescript solution to lc problem: No.2336
No.2336.Smallest Number in Infinite Set
1 parent 3fce2e5 commit 0dd886b

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

solution/2300-2399/2336.Smallest Number in Infinite Set/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,34 @@ func (h *hp) top() int { a := *h; return a[0] }
327327
### **TypeScript**
328328

329329
```ts
330+
class SmallestInfiniteSet {
331+
hashMap;
332+
constructor() {
333+
this.hashMap = new Array(1001).fill(true);
334+
}
335+
336+
popSmallest(): number {
337+
for (let i = 1; i <= 1001; i++) {
338+
if (this.hashMap[i]) {
339+
this.hashMap[i] = false;
340+
return i;
341+
}
342+
}
343+
}
344+
345+
addBack(num: number): void {
346+
if (!this.hashMap[num]) {
347+
this.hashMap[num] = true;
348+
}
349+
}
350+
}
330351

352+
/**
353+
* Your SmallestInfiniteSet object will be instantiated and called as such:
354+
* var obj = new SmallestInfiniteSet()
355+
* var param_1 = obj.popSmallest()
356+
* obj.addBack(num)
357+
*/
331358
```
332359

333360
### **...**

solution/2300-2399/2336.Smallest Number in Infinite Set/README_EN.md

+27
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,34 @@ func (h *hp) top() int { a := *h; return a[0] }
315315
### **TypeScript**
316316

317317
```ts
318+
class SmallestInfiniteSet {
319+
hashMap;
320+
constructor() {
321+
this.hashMap = new Array(1001).fill(true);
322+
}
323+
324+
popSmallest(): number {
325+
for (let i = 1; i <= 1001; i++) {
326+
if (this.hashMap[i]) {
327+
this.hashMap[i] = false;
328+
return i;
329+
}
330+
}
331+
}
332+
333+
addBack(num: number): void {
334+
if (!this.hashMap[num]) {
335+
this.hashMap[num] = true;
336+
}
337+
}
338+
}
318339

340+
/**
341+
* Your SmallestInfiniteSet object will be instantiated and called as such:
342+
* var obj = new SmallestInfiniteSet()
343+
* var param_1 = obj.popSmallest()
344+
* obj.addBack(num)
345+
*/
319346
```
320347

321348
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class SmallestInfiniteSet {
2+
hashMap;
3+
constructor() {
4+
this.hashMap = new Array(1001).fill(true);
5+
}
6+
7+
popSmallest(): number {
8+
for (let i = 1; i <= 1001; i++) {
9+
if (this.hashMap[i]) {
10+
this.hashMap[i] = false;
11+
return i;
12+
}
13+
}
14+
}
15+
16+
addBack(num: number): void {
17+
if (!this.hashMap[num]) {
18+
this.hashMap[num] = true;
19+
}
20+
}
21+
}
22+
23+
/**
24+
* Your SmallestInfiniteSet object will be instantiated and called as such:
25+
* var obj = new SmallestInfiniteSet()
26+
* var param_1 = obj.popSmallest()
27+
* obj.addBack(num)
28+
*/

0 commit comments

Comments
 (0)