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 ...
随机推荐
- php基础函数
函数四要素:返回类型(php没有返回类型), 函数名,参数列表,函数体//php定义函数的方式 简单 例://function show(){// echo "狗头铡伺候" ...
- SetWindowPos和SetForegroundWindow
There are many closely-related concepts involved, and related terms are often misused, even in the o ...
- Python开发规范
背景 Python语言规范 Lint 导入 包 异常 全局变量 嵌套/局部/内部类或函数 列表推导(List Comprehensions) 默认迭代器和操作符 生成器 Lambda 函数 条件表达式 ...
- decimal扩展方法(转换为字符串,去掉末尾的0)
/// <summary> /// 转换为字符串,去掉末尾0 /// </summary> /// <param name="target">被 ...
- 怎样给Win7系统设置一个默认的浏览器
怎样给Win7系统设置一个默认的浏览器.. --------------- 点击桌面左下角「windows图标」,再点击「控制面板」,如图: 点击「程序」,如图: 点击「设置默认程序」,如图: 等到「 ...
- kali系统:局域网arp欺骗, 搞定任意windows计算机
目的 通过Arp欺骗, 给局域网内的所有用户网页中植入木马, 只要用户运行以后, 就会反弹一个shell到我们计算机 准备 kali系统 metaspolit的使用 Arp欺骗工具:bettercap ...
- webstom,zencoding,windows快捷键
1.webstorm快捷键: IntelliJ-Idea 的快捷键 Ctrl+/ 或 Ctrl+Shift+/ 注释(// 或者/*…*/ ) Shift+F6 重构-重命名 Ctrl+X 删除行 C ...
- [WPF]如何调试Data Binding
前言 在WPF开发中,将ViewModel中对象绑定到UI上时,会出现明明已经将数据对象Binding到UI,但是UI上就是不显示等等的问题.这篇博客将介绍WPF Data Binding相关的内容, ...
- github+hexo搭建自己的博客网站(五)进阶配置(畅言实现博客的评论)
如何对如何搭建hexo+github可以查看我第一篇入门文章:http://www.cnblogs.com/chengxs/p/7402174.html 详细的可以查看hexo博客的演示:https: ...
- Spring中实现文件上传
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt110 实现图片上传 用户必须能够上传图片,因此需要文件上传的功能.比较常见 ...