思考:
本题比较简单,是运用广度优先算法,通过队列存储同一深度元素。
public int findBottleLeftValue(TreeNode root){ Queue<TreeNode> q = new LinkedList<TreeNode>(); q.offer(root); int result = 0; while (!q.isEmpty()) { int size = q.size(); result = q.peek().val; while (size>0) { TreeNode tempNode = q.poll(); size--; if(tempNode.left!=null){ q.offer(tempNode.left); } if(tempNode.right!=null){ q.offer(tempNode.right); } } } return result; }
新闻热点
疑难解答