Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ func distMoney(money int, children int) int {
}
```

### **TypeScript**

```ts
function distMoney(money: number, children: number): number {
if (money < children) {
return -1;
}
if (money > 8 * children) {
return children - 1;
}
if (money === 8 * children - 4) {
return children - 2;
}
return Math.floor((money - children) / 7);
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ func distMoney(money int, children int) int {
}
```


### **TypeScript**

```ts
function distMoney(money: number, children: number): number {
if (money < children) {
return -1;
}
if (money > 8 * children) {
return children - 1;
}
if (money === 8 * children - 4) {
return children - 2;
}
return Math.floor((money - children) / 7);
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function distMoney(money: number, children: number): number {
if (money < children) {
return -1;
}
if (money > 8 * children) {
return children - 1;
}
if (money === 8 * children - 4) {
return children - 2;
}
return Math.floor((money - children) / 7);
}
15 changes: 15 additions & 0 deletions solution/2500-2599/2592.Maximize Greatness of an Array/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ func maximizeGreatness(nums []int) int {
}
```

### **TypeScript**

```ts
function maximizeGreatness(nums: number[]): number {
nums.sort((a, b) => a - b);
let i = 0;
for (const x of nums) {
if (x > nums[i]) {
i += 1;
}
}
return i;
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ func maximizeGreatness(nums []int) int {
}
```

### **TypeScript**

```ts
function maximizeGreatness(nums: number[]): number {
nums.sort((a, b) => a - b);
let i = 0;
for (const x of nums) {
if (x > nums[i]) {
i += 1;
}
}
return i;
}
```

### **...**

```
Expand Down
10 changes: 10 additions & 0 deletions solution/2500-2599/2592.Maximize Greatness of an Array/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function maximizeGreatness(nums: number[]): number {
nums.sort((a, b) => a - b);
let i = 0;
for (const x of nums) {
if (x > nums[i]) {
i += 1;
}
}
return i;
}
12 changes: 12 additions & 0 deletions solution/2500-2599/2595.Number of Even and Odd Bits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ func evenOddBit(n int) []int {
}
```

### **TypeScript**

```ts
function evenOddBit(n: number): number[] {
const ans = new Array(2).fill(0);
for (let i = 0; n > 0; n >>= 1, i ^= 1) {
ans[i] += n & 1;
}
return ans;
}
```

### **...**

```
Expand Down
12 changes: 12 additions & 0 deletions solution/2500-2599/2595.Number of Even and Odd Bits/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ func evenOddBit(n int) []int {
}
```

### **TypeScript**

```ts
function evenOddBit(n: number): number[] {
const ans = new Array(2).fill(0);
for (let i = 0; n > 0; n >>= 1, i ^= 1) {
ans[i] += n & 1;
}
return ans;
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function evenOddBit(n: number): number[] {
const ans = new Array(2).fill(0);
for (let i = 0; n > 0; n >>= 1, i ^= 1) {
ans[i] += n & 1;
}
return ans;
}
28 changes: 28 additions & 0 deletions solution/2500-2599/2596.Check Knight Tour Configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,34 @@ func abs(x int) int {
}
```

### **TypeScript**

```ts
function checkValidGrid(grid: number[][]): boolean {
if (grid[0][0] !== 0) {
return false;
}
const n = grid.length;
const pos = Array.from(new Array(n * n), () => new Array(2).fill(0));
for (let i = 0; i < n; ++i) {
for (let j = 0; j < n; ++j) {
pos[grid[i][j]] = [i, j];
}
}
for (let i = 1; i < n * n; ++i) {
const p1 = pos[i - 1];
const p2 = pos[i];
const dx = Math.abs(p1[0] - p2[0]);
const dy = Math.abs(p1[1] - p2[1]);
const ok = (dx === 1 && dy === 2) || (dx === 2 && dy === 1);
if (!ok) {
return false;
}
}
return true;
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,34 @@ func abs(x int) int {
}
```

### **TypeScript**

```ts
function checkValidGrid(grid: number[][]): boolean {
if (grid[0][0] !== 0) {
return false;
}
const n = grid.length;
const pos = Array.from(new Array(n * n), () => new Array(2).fill(0));
for (let i = 0; i < n; ++i) {
for (let j = 0; j < n; ++j) {
pos[grid[i][j]] = [i, j];
}
}
for (let i = 1; i < n * n; ++i) {
const p1 = pos[i - 1];
const p2 = pos[i];
const dx = Math.abs(p1[0] - p2[0]);
const dy = Math.abs(p1[1] - p2[1]);
const ok = (dx === 1 && dy === 2) || (dx === 2 && dy === 1);
if (!ok) {
return false;
}
}
return true;
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function checkValidGrid(grid: number[][]): boolean {
if (grid[0][0] !== 0) {
return false;
}
const n = grid.length;
const pos = Array.from(new Array(n * n), () => new Array(2).fill(0));
for (let i = 0; i < n; ++i) {
for (let j = 0; j < n; ++j) {
pos[grid[i][j]] = [i, j];
}
}
for (let i = 1; i < n * n; ++i) {
const p1 = pos[i - 1];
const p2 = pos[i];
const dx = Math.abs(p1[0] - p2[0]);
const dy = Math.abs(p1[1] - p2[1]);
const ok = (dx === 1 && dy === 2) || (dx === 2 && dy === 1);
if (!ok) {
return false;
}
}
return true;
}
26 changes: 26 additions & 0 deletions solution/2500-2599/2597.The Number of Beautiful Subsets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,32 @@ func beautifulSubsets(nums []int, k int) int {
}
```

### **TypeScript**

```ts
function beautifulSubsets(nums: number[], k: number): number {
let ans: number = -1;
const cnt: number[] = new Array(1010).fill(0);
const n: number = nums.length;
const dfs = (i: number) => {
if (i >= n) {
++ans;
return;
}
dfs(i + 1);
const ok1: boolean = nums[i] + k >= 1010 || cnt[nums[i] + k] === 0;
const ok2: boolean = nums[i] - k < 0 || cnt[nums[i] - k] === 0;
if (ok1 && ok2) {
++cnt[nums[i]];
dfs(i + 1);
--cnt[nums[i]];
}
};
dfs(0);
return ans;
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,32 @@ func beautifulSubsets(nums []int, k int) int {
}
```

### **TypeScript**

```ts
function beautifulSubsets(nums: number[], k: number): number {
let ans: number = -1;
const cnt: number[] = new Array(1010).fill(0);
const n: number = nums.length;
const dfs = (i: number) => {
if (i >= n) {
++ans;
return;
}
dfs(i + 1);
const ok1: boolean = nums[i] + k >= 1010 || cnt[nums[i] + k] === 0;
const ok2: boolean = nums[i] - k < 0 || cnt[nums[i] - k] === 0;
if (ok1 && ok2) {
++cnt[nums[i]];
dfs(i + 1);
--cnt[nums[i]];
}
};
dfs(0);
return ans;
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function beautifulSubsets(nums: number[], k: number): number {
let ans: number = -1;
const cnt: number[] = new Array(1010).fill(0);
const n: number = nums.length;
const dfs = (i: number) => {
if (i >= n) {
++ans;
return;
}
dfs(i + 1);
const ok1: boolean = nums[i] + k >= 1010 || cnt[nums[i] + k] === 0;
const ok2: boolean = nums[i] - k < 0 || cnt[nums[i] - k] === 0;
if (ok1 && ok2) {
++cnt[nums[i]];
dfs(i + 1);
--cnt[nums[i]];
}
};
dfs(0);
return ans;
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ func findSmallestInteger(nums []int, value int) int {
}
```

### **TypeScript**

```ts
function findSmallestInteger(nums: number[], value: number): number {
const cnt: number[] = new Array(value).fill(0);
for (const x of nums) {
++cnt[((x % value) + value) % value];
}
for (let i = 0; ; ++i) {
if (cnt[i % value]-- === 0) {
return i;
}
}
}
```

### **...**

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ func findSmallestInteger(nums []int, value int) int {
}
```

### **TypeScript**

```ts
function findSmallestInteger(nums: number[], value: number): number {
const cnt: number[] = new Array(value).fill(0);
for (const x of nums) {
++cnt[((x % value) + value) % value];
}
for (let i = 0; ; ++i) {
if (cnt[i % value]-- === 0) {
return i;
}
}
}
```

### **...**

```
Expand Down
Loading