File tree
Expand file treeCollapse file tree1 file changed
+14
-0
lines changed Expand file treeCollapse file tree1 file changed
+14
-0
lines changed Original file line number | Diff line number | Diff line change |
---|
|
| 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 | +}; |
You can’t perform that action at this time.
0 commit comments