Minimum Deletions to Make Array Beautiful LeetCode solution in JavaScript

1
var minDeletion = function (nums) {
2
const n = nums.length;
3
const res = [];
4

5
for (let i = 0; i < n; ++i) {
6
const num = nums[i];
7

8
if (res.length % 2 === 0 || res.at(-1) != num) {
9
res.push(num);
10
}
11
}
12

13
if (res.length % 2 === 1) res.pop();
14

15
return n - res.length;
16
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0