Skip to content

Commit 23012a8

Browse files
committed
feat: add ts solution to lc problems
- No.0641.Design Circular Deque - No.1422.Maximum Score After Splitting a String - No.2373.Largest Local Values in a Matrix - No.2374.Node With Highest Edge Score - No.2375.Construct Smallest Number From DI String
1 parent 4c1f48e commit 23012a8

File tree

16 files changed

+760
-4
lines changed

16 files changed

+760
-4
lines changed

solution/0600-0699/0641.Design Circular Deque/README.md

+118
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,124 @@ func (this *MyCircularDeque) IsFull() bool {
451451
*/
452452
```
453453

454+
### **TypeScript**
455+
456+
```ts
457+
class MyCircularDeque {
458+
private vals: number[];
459+
private length: number;
460+
private size: number;
461+
private start: number;
462+
private end: number;
463+
464+
constructor(k: number) {
465+
this.vals = new Array(k).fill(0);
466+
this.start = 0;
467+
this.end = 0;
468+
this.length = 0;
469+
this.size = k;
470+
}
471+
472+
insertFront(value: number): boolean {
473+
if (this.isFull()) {
474+
return false;
475+
}
476+
477+
if (this.start === 0) {
478+
this.start = this.size - 1;
479+
} else {
480+
this.start--;
481+
}
482+
this.vals[this.start] = value;
483+
this.length++;
484+
return true;
485+
}
486+
487+
insertLast(value: number): boolean {
488+
if (this.isFull()) {
489+
return false;
490+
}
491+
492+
this.vals[this.end] = value;
493+
this.length++;
494+
if (this.end + 1 === this.size) {
495+
this.end = 0;
496+
} else {
497+
this.end++;
498+
}
499+
return true;
500+
}
501+
502+
deleteFront(): boolean {
503+
if (this.isEmpty()) {
504+
return false;
505+
}
506+
507+
if (this.start + 1 === this.size) {
508+
this.start = 0;
509+
} else {
510+
this.start++;
511+
}
512+
this.length--;
513+
return true;
514+
}
515+
516+
deleteLast(): boolean {
517+
if (this.isEmpty()) {
518+
return false;
519+
}
520+
521+
if (this.end === 0) {
522+
this.end = this.size - 1;
523+
} else {
524+
this.end--;
525+
}
526+
this.length--;
527+
return true;
528+
}
529+
530+
getFront(): number {
531+
if (this.isEmpty()) {
532+
return -1;
533+
}
534+
535+
return this.vals[this.start];
536+
}
537+
538+
getRear(): number {
539+
if (this.isEmpty()) {
540+
return -1;
541+
}
542+
543+
if (this.end === 0) {
544+
return this.vals[this.size - 1];
545+
}
546+
return this.vals[this.end - 1];
547+
}
548+
549+
isEmpty(): boolean {
550+
return this.length === 0;
551+
}
552+
553+
isFull(): boolean {
554+
return this.length === this.size;
555+
}
556+
}
557+
558+
/**
559+
* Your MyCircularDeque object will be instantiated and called as such:
560+
* var obj = new MyCircularDeque(k)
561+
* var param_1 = obj.insertFront(value)
562+
* var param_2 = obj.insertLast(value)
563+
* var param_3 = obj.deleteFront()
564+
* var param_4 = obj.deleteLast()
565+
* var param_5 = obj.getFront()
566+
* var param_6 = obj.getRear()
567+
* var param_7 = obj.isEmpty()
568+
* var param_8 = obj.isFull()
569+
*/
570+
```
571+
454572
### **...**
455573

456574
```

solution/0600-0699/0641.Design Circular Deque/README_EN.md

+118
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,124 @@ func (this *MyCircularDeque) IsFull() bool {
428428
*/
429429
```
430430

431+
### **TypeScript**
432+
433+
```ts
434+
class MyCircularDeque {
435+
private vals: number[];
436+
private length: number;
437+
private size: number;
438+
private start: number;
439+
private end: number;
440+
441+
constructor(k: number) {
442+
this.vals = new Array(k).fill(0);
443+
this.start = 0;
444+
this.end = 0;
445+
this.length = 0;
446+
this.size = k;
447+
}
448+
449+
insertFront(value: number): boolean {
450+
if (this.isFull()) {
451+
return false;
452+
}
453+
454+
if (this.start === 0) {
455+
this.start = this.size - 1;
456+
} else {
457+
this.start--;
458+
}
459+
this.vals[this.start] = value;
460+
this.length++;
461+
return true;
462+
}
463+
464+
insertLast(value: number): boolean {
465+
if (this.isFull()) {
466+
return false;
467+
}
468+
469+
this.vals[this.end] = value;
470+
this.length++;
471+
if (this.end + 1 === this.size) {
472+
this.end = 0;
473+
} else {
474+
this.end++;
475+
}
476+
return true;
477+
}
478+
479+
deleteFront(): boolean {
480+
if (this.isEmpty()) {
481+
return false;
482+
}
483+
484+
if (this.start + 1 === this.size) {
485+
this.start = 0;
486+
} else {
487+
this.start++;
488+
}
489+
this.length--;
490+
return true;
491+
}
492+
493+
deleteLast(): boolean {
494+
if (this.isEmpty()) {
495+
return false;
496+
}
497+
498+
if (this.end === 0) {
499+
this.end = this.size - 1;
500+
} else {
501+
this.end--;
502+
}
503+
this.length--;
504+
return true;
505+
}
506+
507+
getFront(): number {
508+
if (this.isEmpty()) {
509+
return -1;
510+
}
511+
512+
return this.vals[this.start];
513+
}
514+
515+
getRear(): number {
516+
if (this.isEmpty()) {
517+
return -1;
518+
}
519+
520+
if (this.end === 0) {
521+
return this.vals[this.size - 1];
522+
}
523+
return this.vals[this.end - 1];
524+
}
525+
526+
isEmpty(): boolean {
527+
return this.length === 0;
528+
}
529+
530+
isFull(): boolean {
531+
return this.length === this.size;
532+
}
533+
}
534+
535+
/**
536+
* Your MyCircularDeque object will be instantiated and called as such:
537+
* var obj = new MyCircularDeque(k)
538+
* var param_1 = obj.insertFront(value)
539+
* var param_2 = obj.insertLast(value)
540+
* var param_3 = obj.deleteFront()
541+
* var param_4 = obj.deleteLast()
542+
* var param_5 = obj.getFront()
543+
* var param_6 = obj.getRear()
544+
* var param_7 = obj.isEmpty()
545+
* var param_8 = obj.isFull()
546+
*/
547+
```
548+
431549
### **...**
432550

433551
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
class MyCircularDeque {
2+
private vals: number[];
3+
private length: number;
4+
private size: number;
5+
private start: number;
6+
private end: number;
7+
8+
constructor(k: number) {
9+
this.vals = new Array(k).fill(0);
10+
this.start = 0;
11+
this.end = 0;
12+
this.length = 0;
13+
this.size = k;
14+
}
15+
16+
insertFront(value: number): boolean {
17+
if (this.isFull()) {
18+
return false;
19+
}
20+
21+
if (this.start === 0) {
22+
this.start = this.size - 1;
23+
} else {
24+
this.start--;
25+
}
26+
this.vals[this.start] = value;
27+
this.length++;
28+
return true;
29+
}
30+
31+
insertLast(value: number): boolean {
32+
if (this.isFull()) {
33+
return false;
34+
}
35+
36+
this.vals[this.end] = value;
37+
this.length++;
38+
if (this.end + 1 === this.size) {
39+
this.end = 0;
40+
} else {
41+
this.end++;
42+
}
43+
return true;
44+
}
45+
46+
deleteFront(): boolean {
47+
if (this.isEmpty()) {
48+
return false;
49+
}
50+
51+
if (this.start + 1 === this.size) {
52+
this.start = 0;
53+
} else {
54+
this.start++;
55+
}
56+
this.length--;
57+
return true;
58+
}
59+
60+
deleteLast(): boolean {
61+
if (this.isEmpty()) {
62+
return false;
63+
}
64+
65+
if (this.end === 0) {
66+
this.end = this.size - 1;
67+
} else {
68+
this.end--;
69+
}
70+
this.length--;
71+
return true;
72+
}
73+
74+
getFront(): number {
75+
if (this.isEmpty()) {
76+
return -1;
77+
}
78+
79+
return this.vals[this.start];
80+
}
81+
82+
getRear(): number {
83+
if (this.isEmpty()) {
84+
return -1;
85+
}
86+
87+
if (this.end === 0) {
88+
return this.vals[this.size - 1];
89+
}
90+
return this.vals[this.end - 1];
91+
}
92+
93+
isEmpty(): boolean {
94+
return this.length === 0;
95+
}
96+
97+
isFull(): boolean {
98+
return this.length === this.size;
99+
}
100+
}
101+
102+
/**
103+
* Your MyCircularDeque object will be instantiated and called as such:
104+
* var obj = new MyCircularDeque(k)
105+
* var param_1 = obj.insertFront(value)
106+
* var param_2 = obj.insertLast(value)
107+
* var param_3 = obj.deleteFront()
108+
* var param_4 = obj.deleteLast()
109+
* var param_5 = obj.getFront()
110+
* var param_6 = obj.getRear()
111+
* var param_7 = obj.isEmpty()
112+
* var param_8 = obj.isFull()
113+
*/

0 commit comments

Comments
 (0)