Nested List Weight Sum -- LeetCode 339
Given a nested list of integers, return the sum of all integers in the list weighted by their depth.
Each element is either an integer, or a list -- whose elements may also be integers or other lists.
Example 1:
Given the list [[1,1],2,[1,1]]
, return 10. (four 1's at depth 2, one 2 at depth 1)
Example 2:
Given the list [1,[4,[6]]]
, return 27. (one 1 at depth 1, one 4 at depth 2, and one 6 at depth 3; 1 + 4*2 + 6*3 = 27)
Solution 1:
Solution 2:
Nested List Weight Sum -- LeetCode 339的更多相关文章
- LeetCode 339. Nested List Weight Sum
原题链接在这里:https://leetcode.com/problems/nested-list-weight-sum/ 题目: Given a nested list of integers, r ...
- 【leetcode】339. Nested List Weight Sum
原题 Given a nested list of integers, return the sum of all integers in the list weighted by their dep ...
- [leetcode]364. Nested List Weight Sum II嵌套列表加权和II
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- [LeetCode] Nested List Weight Sum II 嵌套链表权重和之二
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- LeetCode Nested List Weight Sum
原题链接在这里:https://leetcode.com/problems/nested-list-weight-sum/ 题目: Given a nested list of integers, r ...
- [LeetCode] 364. Nested List Weight Sum II 嵌套链表权重和之二
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- LeetCode 364. Nested List Weight Sum II
原题链接在这里:https://leetcode.com/problems/nested-list-weight-sum-ii/description/ 题目: Given a nested list ...
- Nested List Weight Sum I & II
Nested List Weight Sum I Given a nested list of integers, return the sum of all integers in the list ...
- 嵌套列表的加权和 · Nested List Weight Sum
[抄题]: Given a nested list of integers, return the sum of all integers in the list weighted by their ...
随机推荐
- jQuery和Ajax的使用(杂记)
在jsp文件的获取绝对路径标签,其他jsp文件调用就行了 <%@ page language="java" contentType="text/html; char ...
- 隐式意图Intent
在我们想往下一个页面传递数据时,要想到显式意图和隐式意图,显示意图用于内部活动跳转时比较方便,而隐式意图用于应用程序中外部活动的跳转时较为方便,在使用隐式意图时我们要想到清单文件 代码如下: < ...
- pickle与shelve
pickle Example 写入文件 import pickle integers = [1, 2, 3, 4, 5] with open('pickle-example.p', 'wb') as ...
- python之redis
Redis简单介绍 如果简单地比较Redis与Memcached的区别,大多数都会得到以下观点:1 Redis不仅仅支持简单的k/v类型的数据,同时还提供list,set,zset,hash等数据结构 ...
- 批量删除.pyo后缀的文件
find . -name "*.pyo" -exec rm {} \; 删除以.pyo后缀的所有文件 find . ! -name "*.pyo" -exec ...
- c# base关键的理解
base 最大的使用地方在面相对性开发的多态性上.(什么是多态,如何理解多态) base可以[完成]创建派生类实例时调用其基类构造函数或者调用基类上已经被其他方法重写的方法 //关于base调用基类构 ...
- immutableJS一些API
原生js转换为immutableData Immutable.fromJS([1,2]) // immutable的 list Immutable.fromJS({a: 1}) // immutabl ...
- 不支持关键字“metadata”问题的解决方法
不支持关键字“metadata”问题的解决方法 原来的语句: metadata=res://*/Models.CallCenterEntities2.0.csdl|res://*/Models.Cal ...
- sublime_text3配置
推荐视频 http://v.youku.com/v_show/id_XMzU5NzQ5ODgw.html 介绍的是2版本 准备工作 点击连接下载Sublime Text3 初始化用户信息 第一次安装该 ...
- nginx虚拟主机配置
nginx虚拟主机配置 虚拟主机的概念虚拟主机,就是把一台物理服务器划分成多个"虚拟"的服务器,每一个虚拟主机都可以有独立的域名和独立的目录nginx虚拟主机的配置nginx的 ...