问题描述:

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

样例:

给定 [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 {
public:
// @param nestedList a list of NestedInteger
// @return a list of integer
vector<int> result;
vector<int> flatten(const vector<NestedInteger> &nestedList) {
int nums = nestedList.size(); for (int i = ; i < nums; i++) {
if (nestedList[i].isInteger()) {
result.push_back(nestedList[i].getInteger());
} else {
flatten(nestedList[i].getList());
}
}
return result;
}
};

lintcode 平面列表的更多相关文章

  1. lintcode.22 平面列表

    平面列表    描述 笔记 数据 评测 给定一个列表,该列表中的每个要素要么是个列表,要么是整数.将其变成一个只包含整数的简单列表. 注意事项 如果给定的列表中的要素本身也是一个列表,那么它也可以包含 ...

  2. LintCode2016年8月22日算法比赛----平面列表

    平面列表 题目描述 给定一个列表,该列表中的每个要素要么是个列表,要么是整数.将其变成一个只包含整数的简单列表. 注意事项 如果给定的列表中的要素本身也是一个列表,那么它也可以包含列表. 样例 给定 ...

  3. 【翻译】IdentityServer4:基于资源的配置

    这篇文章基于https://leastprivilege.com/2016/12/01/new-in-identityserver4-resource-based-configuration/进行翻译 ...

  4. Numpy常用API

    目录 一.输入和输出 1.1 NumPy二进制文件(NPY,NPZ) 1.2 文本文件 1.3 正则表达式解析 1.4 原始二进制文件 1.5 内存映射文件 1.6 Base-n相关 1.7 数据源 ...

  5. C#6.0语言规范(十九) 文档注释

    C#为程序员提供了一种机制,可以使用包含XML文本的特殊注释语法来记录他们的代码.在源代码文件中,具有特定形式的注释可用于指示工具从这些注释和它们之前的源代码元素生成XML.使用这种语法的注释称为文档 ...

  6. Swift5 语言参考(四) 表达式

    在Swift中,有四种表达式:前缀表达式,二进制表达式,主表达式和后缀表达式.评估表达式会返回一个值,导致副作用,或两者兼而有之. 前缀和二进制表达式允许您将运算符应用于较小的表达式.主要表达式在概念 ...

  7. LintCode2016年8月22日算法比赛----骰子求和

    骰子求和 题目描述 扔n个骰子,向上面的数字之和为 S .给定 Given n,请列出所有可能的 S 值及其相应的概率. 样例 给定n=1,返回 [ [1, 0.17], [2, 0.17], [3, ...

  8. NumPy v1.15手册汉化

    NumPy参考 数组创建 零 和 一 empty(shape[, dtype, order]):返回给定形状和类型的新数组,而不初始化条目 empty_like(prototype[, dtype,  ...

  9. Result Grouping / Field Collapsing-结果分组

    WiKi:http://wiki.apache.org/solr/FieldCollapsing Introduction 字段折叠和结果分组是考虑相同solr功能的两种不同的方式. 字段折叠折叠一组 ...

随机推荐

  1. TCP Flow Control and Data Transfer

    TCP Flow Control TCP Data Transfer Selective Repeat ARQ with Positive ACK Window slides a byte basis ...

  2. keil之编辑环境配置

    1.edit-->configuration 2. 3.开始是:ANSI编码,但一去掉:display modules,中文的注视就乱码了:请教Justchen,把编码改为GB2312,一切恢复 ...

  3. python 爬虫简介以及使用方法

    阶段大纲: 一. 爬虫 1. 基本操作 - 登录任意网站(伪造浏览器的任何行为) 2. 性能相关 - 并发方案: - 异步IO: gevent/Twisted/asyncio/aiohttp - 自定 ...

  4. 免安装版MySQL8数据库的安装

    [环境准备] PC版本:Windows10企业版.64位操作系统 数据库:MySQL8.0.12-win64.zip免安装版 [彻底卸载已安装的MySQL数据库] 由于系统中MySQL数据库的卸载不彻 ...

  5. free -g 说明

    free -g 说明: free -g -/+ buffers/cache 说明: buffer 写缓存,表示脏数据写入磁盘之前缓存一段时间,可以释放.sync命令可以把buffer强制写入硬盘 ca ...

  6. mysqld_safe之三言两语

        today,one buddy in IMG wechat group 2 asked "why i've installed the MySQL 5.7 on linux serv ...

  7. 对布局定位设置-position

    使用position属性,会激活5个属性 left right bottom top z-index(-1至999) 注:z-index:会改变内容的层级关系, 1.绝对定位 position: ab ...

  8. 一、PHP基础-安装PHP集成环境

    目录 PHP运行集成环境下载 phpStudy集成环境安装 XAMPP集成环境安装 WampServer环境安装 作者:吴耀田  个人博客:http://www.cnblogs.com/isaacwy ...

  9. 基于Python的飞机大战游戏

    前几天决定学Python,上网找了教程看了两天,和C比起来面向对象的特性真的都很便捷,有了类开发各种敌机,子弹什么的都很方便. 在此要感谢开发pygame模块的开发人员,真的很好用(逃 效果图↓ 主函 ...

  10. Python值集合操作

    list_l1 = [12,1,4,6,9,5,4,2,11] list_l1 = set(list_l1) print(list_l1,type(list_l1)) #集合也是无序的 list_2 ...