How to write the code with less time complexity for finding the missing element in given array range?
问题 My function should return the missing element in a given array range. So i first sorted the array and checked if the difference between i and i+1 is not equal to 1, i'm returning the missing element. // Given an array A such that: // A[0] = 2 // A[1] = 3 // A[2] = 1 // A[3] = 5 // the function should return 4, as it is the missing element. function solution(A) { A.sort((a,b) => { return b<a; }) var len = A.length; var missing; for( var i = 0; i< len; i++){ if( A[i+1] - A[i] >1){ missing = A[i