0
如何查找數組數組中最長的連續數列?每個數組數組代表結果序列中的一個或零個數字。查找連續數字序列
實施例([]
- 表示陣列(像在JavaScript)):
[
[1, 5, 6],
[7],
[22, 34],
[500, 550],
[60, 1],
[90, 100],
[243],
[250, 110],
[150],
[155],
[160]
]
正確的輸出將是:[1, 7, 22, 60, 90, 110, 150, 155, 160]
詳細輸出:
1, -- index 1 all 1, 5 and 6 would match here, pick the smallest
7, -- index 2
22, -- index 3
-- index 4 skipped, the sequence would end here or wouldn't be the longest possible
60, -- index 5 picked 60, because 1 wouldn't continue in the sequence
90, -- index 6
-- index 7 skipped, the sequence would end here or wouldn't be the longest possible
110, -- index 8
150, -- index 9
155, -- index 10
160 -- index 11
你能解釋一下你是怎麼得到「正確的輸出」?我在這裏沒有看到任何模式... – NickLH
NickLH說什麼。 – Patrick87
@NickLH:看起來像最長的子序列,除了最多可以使用{1,5,6}中的一個,等等。 –