Find any position of a target number in a sorted array. Return -1 if target does not exist. Example Example 1: Input: nums = [1,2,2,4,5,5], target = 2Output: 1 or 2 Example 2: Input: nums = [1,
Input: root = [1,2,3,null,4,null,5], x = 5, y = 4Output: true Input: root = [1,2,3,4], x = 4, y = 3Output: false 思路:就是level order traverse,BFS,记录一下parent, curNode, Depth; /*** Definition for
Input:3/ \9 20/ \15 7Output: [3, 14.5, 11]Explanation:The average value of nodes on level 0 is 3, on level 1 is 14.5, and on level 2 is 11. Hence return [3, 14.5, 11]. 思路:就是一个level order trav
Input:root = [1,2,3,4,null,null,null,5,null,6], k = 2Diagram of binary tree:1/ \2 3/4/5/6Output: 3Explanation: The leaf node with value 3 (and not the leaf node with value 6) is nearest to the no
Lowest Common Ancestor of a Binary Search Tree 思路:这题跟 Lowest Common Ancestor of Binary Tree 一模一样。思路:就是找p的节点在不在左支,或者右支,找到各自左右节点,然后进行比较,如果两者不一样,说明当前的root就是lowest 父节点,如果左边为空,那就都在右边,返回右边的即可,如果右边为空,那就都在左
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 1、递归解法。两行 public int maxDept
重写Android默认Button按钮引发异常: Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class com.example.activity1.TestButton 自定义控件的代码如下,只是简单重写onTouchEvent方法,一直没办法正常使用。
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 题目要求将有序数组转换为一个二元查找树。树的题目大部分都可以采用递归来解决,这道题也不例外。一个二元查找树的左子树上的所有节点都小于根节点,右子树上的所有节点都大于根节点,同时二元查找树左子树和右子树上
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree {3,9,20,#,#,15,7}, 3/ \9 20/ \15 7
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. 求二叉树的最小深度,最小深度定义为从根节点到最近的叶子节点经过的节点个
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 与排序好的数组转化为二分搜索树的题相似,可以先把链表转化为数组在转化为树。 /*** Definition for singly-linked list.* struct
二叉树Z型输出 Given a binary tree, return the zigzag level order traversal of its nodes’ values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given
Given a binary tree, return the inorder traversal of its nodes’ values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,3,2]. Note: Recursive solution is trivial, could you
先序遍历 Given a binary tree, return the preorder traversal of its nodes’ values. For example: Given binary tree {1,#,2,3}, 1 \ 2 3 return [1,2,3]. Note: Recursive solution is trivial, could you do