摘要:
题目链接 103. 二叉树的锯齿形层序遍历 思路1 额外加一个栈来使得访问节点的顺序是逆序的 代码1 class Solution { public List<List<Integer>> zigzagLevelOrder(TreeNode root) { if(root == null){ ret 阅读全文
摘要:
题目链接 102. 二叉树的层序遍历 思路 树的层次遍历模板题,需要使用一个变量来记录每一层的结点个数 代码 class Solution { public List<List<Integer>> levelOrder(TreeNode root) { if(root == null){ retur 阅读全文
摘要:
题目链接 34. 在排序数组中查找元素的第一个和最后一个位置 思路 转自:林小鹿的题解 两套二分查找模板,分别用来查找左边界和右边界 int bsearch_1(int l, int r) { while (l < r) { int mid = (l + r)/2; if (check(mid)) 阅读全文