Skip to content

Commit df2216e

Browse files
authored
feat: add solutions to lc problems: No.2591~2592, No.2595~2598 (#940)
1 parent 216886d commit df2216e

File tree

18 files changed

+313
-0
lines changed

18 files changed

+313
-0
lines changed

solution/2500-2599/2591.Distribute Money to Maximum Children/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,23 @@ func distMoney(money int, children int) int {
144144
}
145145
```
146146

147+
### **TypeScript**
148+
149+
```ts
150+
function distMoney(money: number, children: number): number {
151+
if (money < children) {
152+
return -1;
153+
}
154+
if (money > 8 * children) {
155+
return children - 1;
156+
}
157+
if (money === 8 * children - 4) {
158+
return children - 2;
159+
}
160+
return Math.floor((money - children) / 7);
161+
}
162+
```
163+
147164
### **...**
148165

149166
```

solution/2500-2599/2591.Distribute Money to Maximum Children/README_EN.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,24 @@ func distMoney(money int, children int) int {
124124
}
125125
```
126126

127+
128+
### **TypeScript**
129+
130+
```ts
131+
function distMoney(money: number, children: number): number {
132+
if (money < children) {
133+
return -1;
134+
}
135+
if (money > 8 * children) {
136+
return children - 1;
137+
}
138+
if (money === 8 * children - 4) {
139+
return children - 2;
140+
}
141+
return Math.floor((money - children) / 7);
142+
}
143+
```
144+
127145
### **...**
128146

129147
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function distMoney(money: number, children: number): number {
2+
if (money < children) {
3+
return -1;
4+
}
5+
if (money > 8 * children) {
6+
return children - 1;
7+
}
8+
if (money === 8 * children - 4) {
9+
return children - 2;
10+
}
11+
return Math.floor((money - children) / 7);
12+
}

solution/2500-2599/2592.Maximize Greatness of an Array/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,21 @@ func maximizeGreatness(nums []int) int {
118118
}
119119
```
120120

121+
### **TypeScript**
122+
123+
```ts
124+
function maximizeGreatness(nums: number[]): number {
125+
nums.sort((a, b) => a - b);
126+
let i = 0;
127+
for (const x of nums) {
128+
if (x > nums[i]) {
129+
i += 1;
130+
}
131+
}
132+
return i;
133+
}
134+
```
135+
121136
### **...**
122137

123138
```

solution/2500-2599/2592.Maximize Greatness of an Array/README_EN.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ func maximizeGreatness(nums []int) int {
100100
}
101101
```
102102

103+
### **TypeScript**
104+
105+
```ts
106+
function maximizeGreatness(nums: number[]): number {
107+
nums.sort((a, b) => a - b);
108+
let i = 0;
109+
for (const x of nums) {
110+
if (x > nums[i]) {
111+
i += 1;
112+
}
113+
}
114+
return i;
115+
}
116+
```
117+
103118
### **...**
104119

105120
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function maximizeGreatness(nums: number[]): number {
2+
nums.sort((a, b) => a - b);
3+
let i = 0;
4+
for (const x of nums) {
5+
if (x > nums[i]) {
6+
i += 1;
7+
}
8+
}
9+
return i;
10+
}

solution/2500-2599/2595.Number of Even and Odd Bits/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ func evenOddBit(n int) []int {
113113
}
114114
```
115115

116+
### **TypeScript**
117+
118+
```ts
119+
function evenOddBit(n: number): number[] {
120+
const ans = new Array(2).fill(0);
121+
for (let i = 0; n > 0; n >>= 1, i ^= 1) {
122+
ans[i] += n & 1;
123+
}
124+
return ans;
125+
}
126+
```
127+
116128
### **...**
117129

118130
```

solution/2500-2599/2595.Number of Even and Odd Bits/README_EN.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ func evenOddBit(n int) []int {
9999
}
100100
```
101101

102+
### **TypeScript**
103+
104+
```ts
105+
function evenOddBit(n: number): number[] {
106+
const ans = new Array(2).fill(0);
107+
for (let i = 0; n > 0; n >>= 1, i ^= 1) {
108+
ans[i] += n & 1;
109+
}
110+
return ans;
111+
}
112+
```
113+
102114
### **...**
103115

104116
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function evenOddBit(n: number): number[] {
2+
const ans = new Array(2).fill(0);
3+
for (let i = 0; n > 0; n >>= 1, i ^= 1) {
4+
ans[i] += n & 1;
5+
}
6+
return ans;
7+
}

solution/2500-2599/2596.Check Knight Tour Configuration/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,34 @@ func abs(x int) int {
176176
}
177177
```
178178

179+
### **TypeScript**
180+
181+
```ts
182+
function checkValidGrid(grid: number[][]): boolean {
183+
if (grid[0][0] !== 0) {
184+
return false;
185+
}
186+
const n = grid.length;
187+
const pos = Array.from(new Array(n * n), () => new Array(2).fill(0));
188+
for (let i = 0; i < n; ++i) {
189+
for (let j = 0; j < n; ++j) {
190+
pos[grid[i][j]] = [i, j];
191+
}
192+
}
193+
for (let i = 1; i < n * n; ++i) {
194+
const p1 = pos[i - 1];
195+
const p2 = pos[i];
196+
const dx = Math.abs(p1[0] - p2[0]);
197+
const dy = Math.abs(p1[1] - p2[1]);
198+
const ok = (dx === 1 && dy === 2) || (dx === 2 && dy === 1);
199+
if (!ok) {
200+
return false;
201+
}
202+
}
203+
return true;
204+
}
205+
```
206+
179207
### **...**
180208

181209
```

0 commit comments

Comments
 (0)