File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var minimumPairRemoval = function(n) {
2+
let c = 0;
3+
while (true) {
4+
let mn = Infinity, mi = 0, isSorted = true;
5+
for (let i = 0; i < n.length-1; i++) {
6+
if (n[i] > n[i+1]) isSorted = false;
7+
if (mn > n[i]+n[i+1]) {
8+
mn = n[i]+n[i+1]; mi = i
9+
}
10+
}
11+
if (isSorted) return c;
12+
n[mi] = mn; c++; n.splice(mi+1, 1);
13+
}
14+
};

0 commit comments

Comments
 (0)