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 ...
随机推荐
- Python二分法查找及变种分析
基于Python3 普通二分法查找目标值的index 二分法查找的思路很简单,先确定好列表nums的一头start一尾end,中间值middle根据头尾数值之和用地板除法除以2,即(start + e ...
- MySQL中count(1),count(*),count(col)的区别
count(*)返回行数的时候不管列中的值是不是null,在MyISAM表中,count(*)被优化,因为在MyISAM表中,行数被额外存储了,所以会很快,但是这个时候不能有where条件.innod ...
- SpringMVC中文件的上传(上传到服务器)和下载问题(二)--------下载
一.建立一个简单的jsp页面. 我们在建好的jsp的页面中加入一个超链接:<a href="${pageContext.request.contextPath}/download&qu ...
- 第6天:DIV+CSS页面布局实战
今天我从早上9:00写代码一直写到下午18:00,写的我差点抑郁了,还好最后终于写出了一个完整页面,没有做动画效果,就是练习了一下DIV+CSS布局,做的是福务达(www.zzfwd.cn)的主页,真 ...
- JVM堆内存设置
今天碰到了一个题目,讲的是关于堆内存的问题,题目如下 下面哪种情况会导致持久区jvm堆内存溢出? A.循环上万次的字符串处理 B.在一段代码内申请上百M甚至上G的内存 C.使用CGLib技术直接操 ...
- RDMA调研报告&一点随笔
计算所科研实践随笔 被淹没在论文海里的两个星期. 早上7:10分起床,草草洗漱,7:30出发,开始漫长的1小时通勤.从地铁站的安检口起,队便排的极长,让人看得头皮发麻.下到了轨道旁稍好,但每趟呼啸而来 ...
- HashMap 数组应用面试题(Point)
今天看了一题面试题,以为很简单,不过自己写了遍,没有完全写出来: 题目是这样的: 给定一些 points 和一个 origin,从 points 中找到 k 个离 origin 最近的点.按照距离由小 ...
- PyQt5实现透明电子时钟
# -*- coding: utf-8 -*- import sys from PyQt5 import QtCore from PyQt5 import QtGui from PyQt5 impor ...
- angular验证表单
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>a ...
- 分布式memcached-虚拟节点
1.通过memcached服务器下的不同端口来达到模拟多台服务器的效果 2.假设现在有三台memcached服务器,本地分别使用11211,11212,11213三个端口来模拟 ①打开端口 ②连接端口 ...