摘要: 题目链接 https://leetcode cn.com/problems/binary tree inorder traversal/description/ 题目描述 给定一个二叉树,返回它的中序遍历 示例: 进阶: 递归算法很简单,你可以通过迭代算法完成吗? 题解 采用栈来遍历,一直遍历到最左 阅读全文
posted @ 2018-08-27 13:34 DCREN 阅读(264) 评论(0) 推荐(0)
摘要: 题目链接 https://leetcode cn.com/problems/binary tree pruning/description/ 题目描述 给定二叉树根结点 root ,此外树的每个结点的值要么是 0,要么是 1。 返回移除了所有不包含 1 的子树的原二叉树。 ( 节点 X 的子树为 X 阅读全文
posted @ 2018-08-27 12:40 DCREN 阅读(377) 评论(0) 推荐(0)
摘要: 题目链接 https://leetcode cn.com/problems/maximum depth of binary tree/description/ 题目描述 给定一个二叉树,找出其最大深度。 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。 说明: 叶子节点是指没有子节点的节点。 阅读全文
posted @ 2018-08-27 11:30 DCREN 阅读(211) 评论(0) 推荐(0)
摘要: 题目链接 https://leetcode cn.com/problems/merge two binary trees/description/ 题目描述 给定两个二叉树,想象当你将它们中的一个覆盖到另一个上时,两个二叉树的一些节点便会重叠。 你需要将他们合并为一个新的二叉树。合并的规则是如果两个 阅读全文
posted @ 2018-08-27 11:09 DCREN 阅读(188) 评论(0) 推荐(0)
摘要: 题目链接 https://leetcode cn.com/problems/invert binary tree/description/ 题目描述 翻转一颗二叉树 示例 输入: 输出: ` 题解 使用递归的方式来求解。需要注意的是,在翻转的过程中,注意保存树节点的一个副本,不然在后面的翻转中会存在 阅读全文
posted @ 2018-08-27 09:39 DCREN 阅读(114) 评论(0) 推荐(0)
摘要: 题目链接 https://leetcode cn.com/problems/maximum binary tree/description/ 题目描述 给定一个不含重复元素的整数数组。一个以此数组构建的最大二叉树定义如下: 1. 二叉树的根是数组中的最大元素。 2. 左子树是通过数组中最大值左边部分 阅读全文
posted @ 2018-08-27 09:33 DCREN 阅读(456) 评论(0) 推荐(0)
摘要: Description A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elem 阅读全文
posted @ 2018-07-31 11:34 DCREN 阅读(181) 评论(0) 推荐(0)
摘要: Description Given an unsorted array of integers, find the length of the longest consecutive elements sequence. Your algorithm should run in O(n) compl 阅读全文
posted @ 2018-07-30 14:29 DCREN 阅读(145) 评论(0) 推荐(0)
摘要: Description Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent 阅读全文
posted @ 2018-07-30 12:10 DCREN 阅读(215) 评论(0) 推荐(0)
摘要: Description Given a string, your task is to count how many palindromic substrings in this string. The substrings with different start indexes or end i 阅读全文
posted @ 2018-07-30 10:43 DCREN 阅读(156) 评论(0) 推荐(0)