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 ...
随机推荐
- JQuery中的回调对象
JQuery中的回调对象 回调对象(Callbacks object)模块是JQuery中的一个很基础的模块,很多其他的模块(比如Deferred.Ajax等)都依赖于Callbacks模块的实现.本 ...
- C# 实例练习(第二天)
实例练习 1. 完成简单登录效果,设置用户登录账号密码,清空控制台,进入登录页面,请求用户输入账号.密码和验证码(随机产生),并判断用户输入的信息,给出相应的提示. C#代码如下: 主要知识点: (1 ...
- 给MySQL_5.7 配置环境变量
给MySQL_5.7 配置环境变量... 1.右键我的电脑--选择属性 2.选择高级系统设置 3.根据MySQL的安装路径.来配置MYSQL_HOME环境变量 找到MySQL5.7的安装根目录 4 ...
- 鸟瞰spring
一.spring框架概述: Spring框架主要提供了Ioc容器.AOP.数据访问.Web开发.消息.测试等相关技术的支持. 1.Spring的模块 1)核心容器 Spring-Core:核心工具类, ...
- 阿里 java学习之路
https://maimai.cn/article/detail?fid=96107193&push_id=5603&share_user=http%3A%2F%2Fi9.taou.c ...
- 公司python入职培训流程
时间分为4周,全部自学,仅提供大纲.适用于Web方向:1.Week1:读完<简明Python教程>,适应Python开发环境2.Week2:写个爬虫,需要深入了解re.urllib2.s ...
- caffe cifar10试跑问题总结
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px "Helvetica Neue"; color: #454545 } p. ...
- Java笔记—— 格式化的输入和输出
精确输出 可以用8个字符的宽度和小数点后了两个字符的精度打印x. double x = 10000.0 /3.0; System.out.printf("%8.2f\n",x);/ ...
- 简易版jQuery——mQuery
前面的话 虽然jQuery已经日渐式微,但它里面的许多思想,如选择器.链式调用.方法函数化.取赋值合体等,有的已经变成了标准,有的一直影响到现在.所以,jQuery是一个伟大的前端框架.前端世界日新月 ...
- kickstart部署及使用
Linux运维:kickstart : 矮哥linux运维群:93324526 1.环境检查 [root@m01 ~]# cat /etc/redhat-release CentOS release ...