publicclass二叉树的最大深度 {/*** Definition of TreeNode:*/publicclassTreeNode {publicintval;publicTreeNode left, right;publicTreeNode(intval) {this.val =val;this.left =this.right =null; } }/***@paramroot: The root of binary tree. *@return: An integer.*/publicintmaxDepth(TreeNode ro...
111. Minimum Depth of Binary Tree 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. Note: A leaf is a node with no children. Example: Given binary tree[3,9,20,null,null,1...
[Leetcode] Min Stack 最小栈 Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. getMin() -- Retrieve...
Given binary tree{3,9,20,#,#,15,7}, 3 / \ 9 20 / \ 15 7 return its bottom-up level order traversal as: [ [15,7], [9,20], [3] ] 问题实质:二叉树的层次遍历(即广度优先) 关键点在于遍历上一层的过程把下一层的节点得到,然后再通过节点的list列表读取到每个节点的值,然后把每一层...
For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows. 这是一个数字反转的问题,翻转的思想是将原数不断模10取余再除10,从个位按照移位不断得到各个位置的数字,正好是结果从高位到低位的各个位置的数字,对结果的处理正好和原数相反,不断乘10加余数。
For example, Given1->1->2, return1->2. Given1->1->2->3->3, return1->2->3. 初步构想:处理的对象是Sorted List,既然是已经排好序的链表,所以需要做的就是逐个比较,先将首元素加入到结果链表,然后遍历整个链表,具有相同取值的元素略过,继续比较,遇到不通过的则添加,需要两个指针,一个search指针进...
103. Binary Tree Zigzag Level Order Traversal Given a binary tree, return thezigzag level ordertraversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary tree[3,9,20,null,null,15,7], ...
110. Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the depth of the two subtrees ofeverynode never differ by more than 1. ...
binary_search bit_manipulation breadth_first_search depth_first_search design divide_and_conquer dynamic_programming greedy hashing heap linked_list math reservoir_sampling stack BasicCalculator.java DecodeString.java DecodedStringAtIndex.java ExclusiveTimeOfFunctions.java LargestRectangleInHistogram.java Longest...
Perfect Binary Tree: a binary tree in which all interior nodes have two children and all leave have the same depth Complete Tree: a binary tree in which every levelexcept possibly the lastis full and all nodes in the last level are as far left as possible ...