C++求二叉樹深度的兩種方法

今天在leetcode中碰到了求二叉樹的深度問題,因而總結一下這兩種方法ios 方法一是用遞歸的方法,方法二是藉助隊列和層序遍歷的思想 #include<iostream> #include<queue> using namespace std; //構建二叉樹 struct TreeNode { int val; struct TreeNode *left; struct
相關文章
相關標籤/搜索