美文网首页Lintcode程序员
Lintcode22 Flatten List solution

Lintcode22 Flatten List solution

作者: 代码码着玩 | 来源:发表于2017-03-25 09:36 被阅读44次

【题目描述】

Given a list, each element in the list can be a list or integer. flatten it into a simply list with integers.

Notice:If the element in the given list is a list, it can contain list too.

给定一个列表,该列表中的每个要素要么是个列表,要么是整数。将其变成一个只包含整数的简单列表。

注意:如果给定的列表中的要素本身也是一个列表,那么它也可以包含列表。

【题目链接】

http://www.lintcode.com/en/problem/flatten-list/

【题目解析】

给定 [1,2,[1,2]],返回 [1,2,1,2]。

给定 [4,[3,[2,[1]]]],返回 [4,3,2,1]。

递归解法和非递归解法解答。容易题。

【参考答案】

http://www.jiuzhang.com/solutions/flatten-list/

相关文章

网友评论

    本文标题:Lintcode22 Flatten List solution

    本文链接:https://www.haomeiwen.com/subject/muevnttx.html