[小米OJ] 8. 最少交换次数
求逆序对数即可
function solution(line) { var nums = line.split(","); var res = 0; for (let i = 0; i < nums.length - 1; i++) { for (let j = i + 1; j < nums.length; j++) { if (nums[i] > nums[j]) { res += 1; } } } return res; }
求逆序对数即可
function solution(line) { var nums = line.split(","); var res = 0; for (let i = 0; i < nums.length - 1; i++) { for (let j = i + 1; j < nums.length; j++) { if (nums[i] > nums[j]) { res += 1; } } } return res; }