我的前半生到底要表现出什么逻辑# TVChinese - 中文电视
h*t
1 楼
两种方法底下有很多人都做出来了。最简单的方法是求array的和,求1-1000的和,求两者差。面试的人给我的algorithm是,假设原来的arry是a,另创一个array b, 把a中的element作b 的index: 例如a10的数是3,那末在b3里存1。每次存入1到b里时都check,如果已经有1存入就是重复的那个了。第二题同理可作。
还是希望能拿到on site...
——————————————————————————
应该算很简单的,我实在是比较水,学艺不精:
1) a big array with a thousand elements storing integers from 1 to 1000, not
sorted. One number is duplicated. How do you find the duplicated number
most efficiently.
2) an array with 1000-1 elements storing integers from 1 to 1000, not sorted
. one number is missing in the array. How do you find that missing number in
the most efficient way.
想听听大家的法子,学习学习。晚些时候我来更新interviewer 给我的答案。
还是希望能拿到on site...
——————————————————————————
应该算很简单的,我实在是比较水,学艺不精:
1) a big array with a thousand elements storing integers from 1 to 1000, not
sorted. One number is duplicated. How do you find the duplicated number
most efficiently.
2) an array with 1000-1 elements storing integers from 1 to 1000, not sorted
. one number is missing in the array. How do you find that missing number in
the most efficient way.
想听听大家的法子,学习学习。晚些时候我来更新interviewer 给我的答案。