1.sort the list. 2. Then

iamflying (自食其水果)
Longest seq must either contain the smallest or not contain the smallest.
a) contains the smallest: use for loop to go thru the rest of the list as the second number, you will get the leap size. Try to use this leap size to test how long the seq can go.
b) doesn't contain the smallest number: use tail recursive to go thru the rest of the list.

Worst time complicity: O(n^3). Average should be close to O(n^2) because the inner loop will end when the first missing number is found.
2016-2-9 -05:00
Page address has been copied.
To share, click to copy page address.
Share Online by QR Code

Back To Topic: 一道面试题,大家给出出主意哈,我一点头绪都没有

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习学科技术