Discuss / Java / 练习

练习

Topic source

有序:

static int findMissingNumber(int start, int end, List<Integer> list) {

    int n = start;   

    for (int i:list){

        if (i!=n)

            break;

        n++;

    }

    return  n;

}

无序:

static int findMissingNumber(int start, int end, List<Integer> list) {

        int total = 0;

        for(int i = start; i <= end; i++)

            total += i;

        for(int j:list)

            total -= j;

        return total;

    }


  • 1

Reply