You have 1000 integers. All are less than 1000 and greater or equal to 1. Among them, 999 are distinct and there is one that is found twice. How can you find the duplicate?

Extension to this questions is – if there are some billion numbers are there, and you have enough memory to fit all these numbers. What is the best of to do the same?