问一道面世题# JobHunting - 待字闺中
t*r
1 楼
I have a array which has numbers from 1 to n one number is missing and one
number is duplicated. find those in O(n)
看了career cup
Let arr be the array, d be the duplicate, and m the missing, then we have
(A) N*(N+1)/2 - sum(arr[i]) = d – m
(B) N*(N+1)*(2N+1)/6 - sum(arr[i])^2 = d^2 - m^2
没看懂为啥有B
any thoughs?
number is duplicated. find those in O(n)
看了career cup
Let arr be the array, d be the duplicate, and m the missing, then we have
(A) N*(N+1)/2 - sum(arr[i]) = d – m
(B) N*(N+1)*(2N+1)/6 - sum(arr[i])^2 = d^2 - m^2
没看懂为啥有B
any thoughs?