Skip to content

Commit 396713a

Browse files
authored
feat: update solutions to lc problem: No.3375 (#4341)
1 parent c90ca0e commit 396713a

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

solution/3300-3399/3375.Minimum Operations to Make Array Values Equal to K/README.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,25 @@ func minOperations(nums []int, k int) int {
176176

177177
```ts
178178
function minOperations(nums: number[], k: number): number {
179-
const s = new Set<number>();
180-
let mi = Infinity;
179+
const s = new Set<number>([k]);
181180
for (const x of nums) {
182-
if (x < k) {
183-
return -1;
184-
}
181+
if (x < k) return -1;
182+
s.add(x);
183+
}
184+
return s.size - 1;
185+
}
186+
```
187+
188+
#### JavaScript
189+
190+
```js
191+
function minOperations(nums, k) {
192+
const s = new Set([k]);
193+
for (const x of nums) {
194+
if (x < k) return -1;
185195
s.add(x);
186-
mi = Math.min(mi, x);
187196
}
188-
return s.size - (mi === k ? 1 : 0);
197+
return s.size - 1;
189198
}
190199
```
191200

solution/3300-3399/3375.Minimum Operations to Make Array Values Equal to K/README_EN.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,25 @@ func minOperations(nums []int, k int) int {
174174

175175
```ts
176176
function minOperations(nums: number[], k: number): number {
177-
const s = new Set<number>();
178-
let mi = Infinity;
177+
const s = new Set<number>([k]);
179178
for (const x of nums) {
180-
if (x < k) {
181-
return -1;
182-
}
179+
if (x < k) return -1;
180+
s.add(x);
181+
}
182+
return s.size - 1;
183+
}
184+
```
185+
186+
#### JavaScript
187+
188+
```js
189+
function minOperations(nums, k) {
190+
const s = new Set([k]);
191+
for (const x of nums) {
192+
if (x < k) return -1;
183193
s.add(x);
184-
mi = Math.min(mi, x);
185194
}
186-
return s.size - (mi === k ? 1 : 0);
195+
return s.size - 1;
187196
}
188197
```
189198

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function minOperations(nums, k) {
2+
const s = new Set([k]);
3+
for (const x of nums) {
4+
if (x < k) return -1;
5+
s.add(x);
6+
}
7+
return s.size - 1;
8+
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
function minOperations(nums: number[], k: number): number {
2-
const s = new Set<number>();
3-
let mi = Infinity;
2+
const s = new Set<number>([k]);
43
for (const x of nums) {
5-
if (x < k) {
6-
return -1;
7-
}
4+
if (x < k) return -1;
85
s.add(x);
9-
mi = Math.min(mi, x);
106
}
11-
return s.size - (mi === k ? 1 : 0);
7+
return s.size - 1;
128
}

0 commit comments

Comments
 (0)