2014-05-06 07:56

题目链接

原题:

Flatten an iterator of iterators in Java. If the input is [ [,], [,[,]], ], it should return [,,,,,]. Implement hasNext() and next(). Note that the inner iterator or list might be empty.

题目:给定一个动态类型的数组,把其中的数组全部展开,成为一个一维数组。

解法:严格类型语言显然不允许这种数据,所以我用Python写了一版代码。

代码:

 # http://www.careercup.com/question?id=5898529851572224
#!/usr/bin/python def flatten(container, new_container):
for element in container:
if isinstance(element, list) or isinstance(element, tuple) or isinstance(element, set):
flatten(element, new_container)
else:
new_container.append(element)
pass if __name__ == '__main__':
a = [1, 2.3, [3, [1, 222]], (4, 111, 0), "string", set([1, "hello", 3.33])]
res = []
flatten(a, res)
print(res)
pass

Careercup - Google面试题 - 5898529851572224的更多相关文章

  1. Careercup - Google面试题 - 5732809947742208

    2014-05-03 22:10 题目链接 原题: Given a dictionary, and a list of letters ( or consider as a string), find ...

  2. Careercup - Google面试题 - 5085331422445568

    2014-05-08 23:45 题目链接 原题: How would you use Dijkstra's algorithm to solve travel salesman problem, w ...

  3. Careercup - Google面试题 - 4847954317803520

    2014-05-08 21:33 题目链接 原题: largest number that an int variable can fit given a memory of certain size ...

  4. Careercup - Google面试题 - 6332750214725632

    2014-05-06 10:18 题目链接 原题: Given a ,) (,) (,), (,) should be returned. Some suggest to use Interval T ...

  5. Careercup - Google面试题 - 5634470967246848

    2014-05-06 07:11 题目链接 原题: Find a shortest path ,) to (N,N), assume is destination, use memorization ...

  6. Careercup - Google面试题 - 5680330589601792

    2014-05-08 23:18 题目链接 原题: If you have data coming in rapid succession what is the best way of dealin ...

  7. Careercup - Google面试题 - 5424071030341632

    2014-05-08 22:55 题目链接 原题: Given a list of strings. Produce a list of the longest common suffixes. If ...

  8. Careercup - Google面试题 - 5377673471721472

    2014-05-08 22:42 题目链接 原题: How would you split a search query across multiple machines? 题目:如何把一个搜索que ...

  9. Careercup - Google面试题 - 6331648220069888

    2014-05-08 22:27 题目链接 原题: What's the tracking algorithm of nearest location to some friends that are ...

随机推荐

  1. JavaScript高级 面向对象的程序设计 (一)《JavaScript高级程序设计(第三版)》

    创建对象 继承 面向对象的语言都有一个表示---类.通过类我们可以创建多个具有相同属性的对象.但是,在JS中并没有类的概念,所以JS的对象也和其他语言的对象不同. 对象的定义:无序的属性集合,其属性可 ...

  2. 标准的CSS盒子模型?与低版本IE的盒子模型有什么不同的?

    CSS盒子模型:由四个属性组成的外边距(margin).内边距(padding).边界(border).内容区(width和height); 标准的CSS盒子模型和低端IE CSS盒子模型不同:宽高不 ...

  3. memcache和memcahced的区别

    Memcache是什么?Memcache是一个自由和开放源代码.高性能.分配的内存对象缓存系统.用于加速动态web应用程序,减轻数据库负载.它可以应对任意多个连接,使用非阻塞的网络IO.由于它的工作机 ...

  4. ASPX页面包含inc文件、用户控件、普通html文件

    如果你是从asp程序员转过来一定不习惯.net的编程风格吧,代码和页面时分离的,asp和php里面时常是引入, 比如<!--#include File="xxxxxxx"-- ...

  5. SQL中迁移sql用户及密码脚本

    SQL中迁移sql用户及密码脚本   编写人:CC阿爸 2014-6-20 在日常SQL数据库的操作中,常常需要迁移数据库或重装服务器,这时候,一些之前建立的login账户,必须重新建立,以下可以通过 ...

  6. 未能加载文件或程序集“Oracle.Web, Version=2.112.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342”或它的某一个依赖项

    当前系统环境描述: Win7x64+VS2012+IIS7 当前情况描述: 发布Web服务,在浏览的时候出现以下问题:未能加载文件或程序集“Oracle.Web, Version=2.112.1.0, ...

  7. 6)Java中String类

    1)String对象的初始化   由于String对象特别常用,所以在对String对象进行初始化时,Java提供了一种简化的特殊语法,格式如下:     String s = “abc”;     ...

  8. C# 调用系统API 内核 简单样例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  9. python 从private key pem文件中加载public key

    import rsa import logging from Crypto.PublicKey import RSA class RsaUtil: def __init__(self, pem_fil ...

  10. IIS 配置错误解决方法集合

    问题:405 - 不允许用于访问此页的 HTTP 谓词 解决:IIS处理程序映射中添加模块映射,模块选择:ServerSideIncludeModule,名称:SSINC-HTML