111. Minimum Depth of Binary Tree
来源:互联网 发布:excel数据透视表分析 编辑:程序博客网 时间:2024/05/29 09:43
Given a binary tree, find its minimum depth.
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
求最小深度
/** * 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: int depth = 1e8; int minDepth(TreeNode* root) { if(root == NULL) return 0; DFS(root); return depth; } int d = 0; void DFS(TreeNode* root) { d++; if(root->left == NULL && root->right == NULL) { if(d < depth) depth = d; return; } if(root->left) { DFS(root->left); d--; } if(root->right) { DFS(root->right); d--; } }};
阅读全文
0 0
- LeetCode 111. Minimum Depth of Binary Tree
- [LeetCode]111.Minimum Depth of Binary Tree
- 【LeetCode】111.Minimum Depth of Binary Tree
- [Leetcode] 111. Minimum Depth of Binary Tree
- 111.Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- [leetcode] 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree LeetCode
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 【LeetCode】111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- LeetCode *** 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- C++函数
- next()和nextLine()的区别详解
- linux-清空文件内容的三种方法
- 第九期 使用 Keras 在游戏中实现自动驾驶 《显卡就是开发板》
- Python核心编程 第一章--正则表达式
- 111. Minimum Depth of Binary Tree
- android Pixelflinger
- 深度学习在信息隐藏中的应用(下)
- arm64_device_init
- 最小生成树算法
- (转)Linux 下 SSH 命令实例指南
- python array.shape
- Redis入门
- SpringBoot入门-快速搭建web服务