摘要: 空间复杂度O(h)而不是O(n),因此不能直接在初始化函数中做中序遍历将结果存储到数组中。next()和hasNext()时间复杂度为O(1)首先本题很容易想到用二叉树的中序遍历去解决,外加注意点1.我们得到思路:仅仅将中序遍历最小值之前的节点压入栈中,当next时我们将栈顶元素取出即为最小值返回, 阅读全文
posted @ 2019-12-06 19:54 任仁人 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 验证二叉搜索树 * * https://leetcode-cn.com/problems/validate-binary-search-tree/description/ * * algorithms * Medium (27.95%) * Likes: 340 * Dislikes: 0 * To 阅读全文
posted @ 2019-12-06 16:47 任仁人 阅读(111) 评论(0) 推荐(0) 编辑
摘要: * @lc app=leetcode.cn id=236 lang=cpp * * [236] 二叉树的最近公共祖先 * * https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/description/ * 阅读全文
posted @ 2019-12-06 11:45 任仁人 阅读(128) 评论(0) 推荐(0) 编辑