lintcode.22 平面列表
平面列表
给定一个列表,该列表中的每个要素要么是个列表,要么是整数。将其变成一个只包含整数的简单列表。
注意事项
如果给定的列表中的要素本身也是一个列表,那么它也可以包含列表。
给定 [1,2,[1,2]],返回 [1,2,1,2]。
[4,[3,[2,[1]]]],返回 [4,3,2,1]/**
* // This is the interface that allows for creating nested lists.
* // You should not implement it, or speculate about its implementation
* class NestedInteger {
* public:
* // Return true if this NestedInteger holds a single integer,
* // rather than a nested list.
* bool isInteger() const;
*
* // Return the single integer that this NestedInteger holds,
* // if it holds a single integer
* // The result is undefined if this NestedInteger holds a nested list
* int getInteger() const;
*
* // Return the nested list that this NestedInteger holds,
* // if it holds a nested list
* // The result is undefined if this NestedInteger holds a single integer
* const vector<NestedInteger> &getList() const;
* };
*/
class Solution {
vector<int> res;
public:
// @param nestedList a list of NestedInteger
// @return a list of integer
vector<int> flatten(const vector<NestedInteger> &nestedList) {
// Write your code here
int size = nestedList.size();
for( int i = 0 ; i < size ; i++ ){
if(nestedList[i].isInteger() ){
res.push_back(nestedList[i].getInteger() );
}
else{
flatten(nestedList[i].getList());
}
}
return res;
}
};
lintcode.22 平面列表的更多相关文章
- LintCode2016年8月22日算法比赛----平面列表
平面列表 题目描述 给定一个列表,该列表中的每个要素要么是个列表,要么是整数.将其变成一个只包含整数的简单列表. 注意事项 如果给定的列表中的要素本身也是一个列表,那么它也可以包含列表. 样例 给定 ...
- [实战]MVC5+EF6+MySql企业网盘实战(22)——图片列表
写在前面 实现逻辑是:单击图片节点,加载所有的当前用户之前上传的图片,分页,按时间倒序加载. 系列文章 [EF]vs15+ef6+mysql code first方式 [实战]MVC5+EF6+MyS ...
- lintcode 平面列表
问题描述: 给定一个列表,该列表中的每个要素要么是个列表,要么是整数.将其变成一个只包含整数的简单列表. 样例: 给定 [1,2,[1,2]],返回 [1,2,1,2]. 给定 [4,[3,[2,[1 ...
- Lesson 2-2(列表,元组)
2.3 列表 2.3.1 列表的创建方法 --- 使用方括号 [] ,括号中的元素之间使用逗号隔开. >>> [1, 2, 3, 4, 5] [1, 2, 3, 4, 5] > ...
- 5.22 HTML 列表标签和表单标签
1,ul无序列表 标签 ul:unordered list ,就是无序列表的意思. li: listitem 列表项的意思.无序列表的每一项都是<li>. <!DOCTYPE h ...
- 22 WPF列表,树,网格
ListView ListView从ListBox派生,只增加了View属性.如果你没有设置View属性,ListView行为正如ListBox. 从技术上,View属性指向任何ViewBase派生类 ...
- lintcode- 22.平面表
题目描述 22. 平面列表 给定一个列表,该列表中的每个要素要么是个列表,要么是整数.将其变成一个只包含整数的简单列表. 样例 给定 [1,2,[1,2]],返回 [1,2,1,2]. 给定 [4,[ ...
- 基本数据类型-列表_元组_字典_day4
一.列表(list)书写格式:[] #通过list类创建的 li = [1, 12, 9, ", 10, ],"庞麦郎"], "ales", True ...
- [实战]MVC5+EF6+MySql企业网盘实战(28)——其他列表
写在前面 本篇文章将实现,其他文件类型的列表. 系列文章 [EF]vs15+ef6+mysql code first方式 [实战]MVC5+EF6+MySql企业网盘实战(1) [实战]MVC5+EF ...
随机推荐
- OpenTK教程-2绘制一个三角形(正确的方法)
上一个教程向我们展示了如何在屏幕上画一个三角形.但是,我说过,那是一种古老的方式,即使它能够正常运行,但是现在这已经不是"正确"的方式.上篇文章中我们将几何发送到GPU的方式是所谓 ...
- AVL树的插入与删除
AVL 树要在插入和删除结点后保持平衡,旋转操作必不可少.关键是理解什么时候应该左旋.右旋和双旋.在Youtube上看到一位老师的视频对这个概念讲解得非常清楚,再结合算法书和网络的博文,记录如下. 1 ...
- Fedora25 将eclipse的快捷方式添加到Applications中
[root@localhost Downloads]# vi /usr/share/applications/eclipse.desktop 然后在里面添加如下内容: [Desktop Entry]N ...
- 【Ubuntu 16】 wifi连接 并解决无桌面图标问题
笔记本上装了win10和ubuntu16双系统,ubuntu16有半年多没使用了,今天一登录成功后,没有桌面啦,一个干净的壁纸映入眼帘,真操蛋. 上网搜索后总结:应该是应用软件中心出了问题,可是,没法 ...
- RedHat 7 常用命令总结
Linux RedHat 7常用命令总结... ----------------------- 征服Linux从终端开始 ------------------------------------- 在 ...
- 第三篇--Jmeter测试数据库Mysql
Jmeter模拟100用户访问Mysql数据库 1.将Mysql数据库的驱动[mysql-connector-java-5.1.15-bin.jar]放到jmeter的lib目录下,新建线程组100[ ...
- 论述Redis和Memcached的差异
原文 https://yq.aliyun.com/articles/60981?utm_campaign=wenzhang&utm_medium=article&utm_source= ...
- 网络协议TFTP
TFTP(Trivial File Transfer Protocol,简单文件传输协议)是TCP/IP协议族中的一个用来在客户端与服务器之间进行简单文件传输的协议.和使用TCP的文件传输协议(FTP ...
- MySQL索引选择及规则整理
索引选择性就是结果个数与总个数的比值. 用sql语句表示为: SELECT COUNT(*) FROM table_name WHERE column_name/SELECT COUNT(*) FRO ...
- Git 入门篇
什么是Git Git是Linux发明者Linus开发的一款新时代的版本控制系统. Git安装 Mac:https://sourceforge.net/projects/git-osx-instal ...