📌  相关文章
📜  挑选号码hackerrank解决方案javascript代码示例

📅  最后修改于: 2022-03-11 15:03:26.209000             🧑  作者: Mango

代码示例1
// picking numbers hackerrank solution javascript
function pickingNumbers(a) {
    // Write your code here
    let sorted = a.sort(function(a, b) {
        return a - b;
    });
    
    let i = 0;
    let j = 1;
    
    while(i < sorted.length && j < sorted.length) {
        if(Math.abs(sorted[i] - sorted[j]) > 1) {
            i++;
            j++;
        } else {
            j++;
        }
    }
   
    return Math.abs(i - j);
}