[LeetCode]Find Bottom Left Tree Value
Given a binary tree, find the leftmost value in the last row of the tree.
Example 1:
Input:2
/ \
1 3Output:
1
Example 2:
Input:1
/ \
2 3
/ / \
4 5 6
/
7
Output:
7
class Solution {
public:
int pivotIndex(vector<int>& nums) {
if(nums.size()<3) return -1;
int sum[nums.size()], max;
for(int i = 0; i < nums.size(); i ++){
i == 0?sum[i] = nums[i] : sum[i] = nums[i] + sum[i-1];
}
max = sum[nums.size()-1];
for(int i = 0; i < nums.size(); i++){
if(max - sum[i] == sum[i] - nums[i]){
return i;
}
}
return -1;
}
};
[LeetCode]Find Bottom Left Tree Value的更多相关文章
- [LeetCode] Find Bottom Left Tree Value 寻找最左下树结点的值
Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / \ 1 ...
- LeetCode——Find Bottom Left Tree Value
Question Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: ...
- leetcode算法: Find Bottom Left Tree Value
leetcode算法: Find Bottom Left Tree ValueGiven a binary tree, find the leftmost value in the last row ...
- Leetcode之深度优先搜索(DFS)专题-513. 找树左下角的值(Find Bottom Left Tree Value)
Leetcode之深度优先搜索(DFS)专题-513. 找树左下角的值(Find Bottom Left Tree Value) 深度优先搜索的解题详细介绍,点击 给定一个二叉树,在树的最后一行找到最 ...
- LeetCode 513. 找树左下角的值(Find Bottom Left Tree Value)
513. 找树左下角的值 513. Find Bottom Left Tree Value 题目描述 给定一个二叉树,在树的最后一行找到最左边的值. LeetCode513. Find Bottom ...
- LN : leetcode 513 Find Bottom Left Tree Value
lc 513 Find Bottom Left Tree Value 513 Find Bottom Left Tree Value Given a binary tree, find the lef ...
- 513. Find Bottom Left Tree Value - LeetCode
Question 513. Find Bottom Left Tree Value Solution 题目大意: 给一个二叉树,求最底层,最左侧节点的值 思路: 按层遍历二叉树,每一层第一个被访问的节 ...
- 【LEETCODE OJ】Binary Tree Postorder Traversal
Problem Link: http://oj.leetcode.com/problems/binary-tree-postorder-traversal/ The post-order-traver ...
- 【LeetCode】199. Binary Tree Right Side View 解题报告(Python)
[LeetCode]199. Binary Tree Right Side View 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/probl ...
随机推荐
- excel冻结窗口
Excel中如果输入内容太多,希望滚动时候,可以看到表头,需要冻结表格.如果我们选中C3表格,执行冻结操作,会看到C3左边和上边有两条直线,这样C3的左边和上边的表格都没法变动,因此冻结表格只能冻结首 ...
- 【javascrpt】——图片预览和上传,兼容IE 9-
下载DEMO:https://github.com/CaptainLiao/zujian/tree/master/Upload 对于现代浏览器来说,要实现图片预览非常简单: 1.fileReader. ...
- springBoot整合MyBatise及简单应用
springBoot整合MyBatise及简单应用 我采用的是 工具IDEA 框架是springBoot+maven+Mybatise 第一步: pom.xml 引入相关jar包 <?xml v ...
- CentOS7基础建站指南(笔记)
由于前段时间腾讯云打折,所以买了一台小服务器,想着以后写几个小网站,博客什么的,但是一开始就遇到了难题,大概就是Linux服务器的配置问题,比如如何假设服务器,配置非root用户,配置服务器数据的非r ...
- Optional类
参照: 一篇简单使用介绍 官网详细用法介绍 包含各种例子的cheetsheet 一个封装某个value的容器 一般可用于方法返回值类型,提醒调用方,这个值可能为null,所以需要处理(因为空指针异常是 ...
- node.js常用命令
安装node 验证是否安装node $node -v $npm -v npm node package manager , Node 的包管理器 安装 包 # 安装到当前目录 $ npm instal ...
- jsp页面用struts2标签展示List<Object>类型的数据
今天遇到一个问题,一个List<Object>类型的数据,是直接从sql查出来的数据,要在前端展示,原来的方法不知道为什么不能展示,后来找了好久,找到了一个靠谱的方法,记录一下 <s ...
- 升级vue-cli为 cli3 并创建项目
一.升级npm install -g @vue/cli 二.创建项目 1.vue create vue3-project 下面会提示让你配置下自己想要用到的功能,然后它会自动帮你安装,这个看自己需求 ...
- Iviews视频搜索引擎
随着视频类型的增加和数据量的日益庞大,如何有效地组织和管理这些数据,使人们能够方便地从大量视频数据中找到自己感兴趣的相关视频片段已成为一种迫切的需求,而能够满足这一需求的技术便是目前人们普遍关注的基于 ...
- Django中-事务操作
如何在Django中进行事务操作呢? 近期,公司里要使用Django开发一套金融相关的系统. 涉及钱了.....安全安全安全 如果钱转到一半,系统崩了,咋办? 如果钱汇到一半,系统崩了,咋办? 如果东 ...