这些数存在哪里呢? 就是计算空间复杂度的时候,计不计入图灵机上input tape 的空间使用数。 当然我猜想你这里是要求用实际的程序,不过也有类似问题。 |
数组是 read only 的。可用内存是指数组以外能存能取的部分。 还忘了一个条件:程序的速度要求是 O(n)。 |
Interesting question, can you hold off posting your answer? |
Hmmm, another ++++ problem. I'd like to try to solve them in the same order as they were raised. |
If there is only one redundant number, sum up the array. The number is Sum(array)-(1+2+..+(n-1)). If there are two redundant numbers, calculate the usual sum and the sum of squares, we can resolve the two redundant numbers by solving two equations. If the number of redundant numbers is unspecified and n can be arbitrarily large, I don't know how to do it in O(n). |
欢迎光临 珍珠湾ART (http://zzwav.com/) | Powered by Discuz! X3 |