题目描述:求二叉树的深度。 1234567891011import Foundationclass For39Solution { func treeDepth(_ root: TreeNode?) -> Int { if root == nil { return 0 } return max(treeDepth(root?.left), treeDepth(root?.right)) + 1 }} 算法思想:递归求,每次+1,利用栈的特性。 github地址:https://github.com/cubegao/LeetCode Tags: 算法 ← Swift.和为S的两个数字VS和为S的连续正数序列 Swift.翻转单词顺序VS左旋转字符串 → 扫描二维码,分享此文章