更新时间:2021-09-15 22:30:09
正如你所知道的整数,使所有这些的总和:
As you know the integers, make a sum of all of them:
(1+N)*N/2 = (1+100)*100/2 = 5050
现在substract那些数组中的总和( S'的)。所不同的将是一个缺少一些你追求(让 X = 5050 - S'
)。
时间复杂度为O(N),并不能得到解决得更快,因为你一定要读阵列一次。
Time complexity is O(N) and can't be solved faster, because you definitely need to read the array once.