Skip to content

Commit 25660e9

Browse files
committedJan 30, 2022
feat: add ts solutions to lc problem: No.2154-2155
2154.Keep Multiplying Found Values by Two 2155.All Divisions With the Highest Score of a Binary Array
1 parent 8524b9a commit 25660e9

File tree

6 files changed

+87
-4
lines changed

6 files changed

+87
-4
lines changed
 

‎solution/2100-2199/2154.Keep Multiplying Found Values by Two/README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@
7575
### **TypeScript**
7676

7777
```ts
78-
78+
function findFinalValue(nums: number[], original: number): number {
79+
let set: Set<number> = new Set(nums);
80+
while (set.has(original)) {
81+
original *= 2;
82+
}
83+
return original;
84+
};
7985
```
8086

8187
### **...**

‎solution/2100-2199/2154.Keep Multiplying Found Values by Two/README_EN.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@
6565
### **TypeScript**
6666

6767
```ts
68-
68+
function findFinalValue(nums: number[], original: number): number {
69+
let set: Set<number> = new Set(nums);
70+
while (set.has(original)) {
71+
original *= 2;
72+
}
73+
return original;
74+
};
6975
```
7076

7177
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function findFinalValue(nums: number[], original: number): number {
2+
let set: Set<number> = new Set(nums);
3+
while (set.has(original)) {
4+
original *= 2;
5+
}
6+
return original;
7+
};

‎solution/2100-2199/2155.All Divisions With the Highest Score of a Binary Array/README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,28 @@
9191
### **TypeScript**
9292

9393
```ts
94-
94+
function maxScoreIndices(nums: number[]): number[] {
95+
const n = nums.length;
96+
const total = nums.reduce((a, c) => a + c, 0);
97+
let left = 0, right = total;
98+
let record: Array<number> = [total];
99+
for (const num of nums) {
100+
if (num == 0) {
101+
left++;
102+
} else {
103+
right--;
104+
}
105+
record.push(left + right);
106+
}
107+
const max = Math.max(...record);
108+
let ans: Array<number> = [];
109+
for (let i = 0; i <= n; i++) {
110+
if (record[i] == max) {
111+
ans.push(i);
112+
}
113+
}
114+
return ans;
115+
};
95116
```
96117

97118
### **...**

‎solution/2100-2199/2155.All Divisions With the Highest Score of a Binary Array/README_EN.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,28 @@ Only index 0 has the highest possible division score 2.
8484
### **TypeScript**
8585

8686
```ts
87-
87+
function maxScoreIndices(nums: number[]): number[] {
88+
const n = nums.length;
89+
const total = nums.reduce((a, c) => a + c, 0);
90+
let left = 0, right = total;
91+
let record: Array<number> = [total];
92+
for (const num of nums) {
93+
if (num == 0) {
94+
left++;
95+
} else {
96+
right--;
97+
}
98+
record.push(left + right);
99+
}
100+
const max = Math.max(...record);
101+
let ans: Array<number> = [];
102+
for (let i = 0; i <= n; i++) {
103+
if (record[i] == max) {
104+
ans.push(i);
105+
}
106+
}
107+
return ans;
108+
};
88109
```
89110

90111
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function maxScoreIndices(nums: number[]): number[] {
2+
const n = nums.length;
3+
const total = nums.reduce((a, c) => a + c, 0);
4+
let left = 0, right = total;
5+
let record: Array<number> = [total];
6+
for (const num of nums) {
7+
if (num == 0) {
8+
left++;
9+
} else {
10+
right--;
11+
}
12+
record.push(left + right);
13+
}
14+
const max = Math.max(...record);
15+
let ans: Array<number> = [];
16+
for (let i = 0; i <= n; i++) {
17+
if (record[i] == max) {
18+
ans.push(i);
19+
}
20+
}
21+
return ans;
22+
};

0 commit comments

Comments
 (0)