leetcode-515. Find Largest Value in Each Tree Row
来源:互联网 发布:两个蓝牙单片机通信 编辑:程序博客网 时间:2024/05/18 03:43
利用队列;
代码:
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: vector<int> largestValues(TreeNode* root) { vector<int> ret; if (root==NULL) return ret; queue<TreeNode*> q; q.push(root); while (q.size()) { int len = q.size(); int maxi = INT_MIN; for (int i=0; i<len; i++) { TreeNode * temp = q.front(); q.pop(); if (temp->val > maxi) maxi = temp->val; if (temp->left) q.push(temp->left); if (temp->right) q.push(temp->right); } ret.push_back(maxi); } return ret; }};
1 0
- LeetCode 515. Find Largest Value in Each Tree Row
- LeetCode OJ 515. Find Largest Value in Each Tree Row
- LeetCode笔记:515. Find Largest Value in Each Tree Row
- [leetcode] 515. Find Largest Value in Each Tree Row
- 【LeetCode】515. Find Largest Value in Each Tree Row
- LeetCode;515. Find Largest Value in Each Tree Row
- leetcode 515. Find Largest Value in Each Tree Row
- leetcode 515. Find Largest Value in Each Tree Row
- leetcode-515. Find Largest Value in Each Tree Row
- leetcode 515. Find Largest Value in Each Tree Row
- leetcode 515. Find Largest Value in Each Tree Row
- leetcode 515. Find Largest Value in Each Tree Row
- LeetCode 515. Find Largest Value in Each Tree Row (C++)
- leetcode 515. Find Largest Value in Each Tree Row
- LeetCode#515. Find Largest Value in Each Tree Row
- leetcode 515. Find Largest Value in Each Tree Row
- LeetCode 515. Find Largest Value in Each Tree Row
- [LeetCode] 515. Find Largest Value in Each Tree Row
- WAVE文件格式
- Fragment中传入数据
- CoreData单表创建使用
- React Native Switch和Picker的认识
- oracle中的会话与事务的区别
- leetcode-515. Find Largest Value in Each Tree Row
- 恢复旋转排序数组
- vue.js 初体验
- 学习淘淘商城第二十二课(KindEditor富文本编辑器的使用)
- Eclipse中设置作者日期等信息
- 使用不同方法查找数组中某个特定值(对象),并计算时间(个人练习)
- linux启动级别
- 浅谈JavaScript实现关键字文本高亮显示
- flask笔记:12:flask与nodejs通讯跨域问题解决