![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
notyour_tracy
多数人为了逃避真正的思考愿意做任何事情——王兴
展开
-
【算法】从前序与中序遍历序列构造二叉树
从前序与中序遍历序列构造二叉树 题目 思路 二叉树相关的题目一般会马上想到递归 这里也一样,分别递归重建获得二叉树 重点:找到中序遍历中根节点位置的索引 重点api: Arrays.copyOfRange(preorder, x , y);// copy的是一个左开右闭的区间 [x,y) 代码 class Solution { public TreeNode buildTree(int[] preorder, int[] inorder) { if(preorder == nu原创 2021-04-24 09:52:05 · 62 阅读 · 0 评论 -
【算法】螺旋矩阵
LeetCode-螺旋矩阵 题目 思路 核心: 用数组 dx/dy(direction of X/Y) 记录坐标x,y在移动的过程中的变化量 int[] dx = {0,1,0,-1}; int[] dy = {1,0,-1,0}; 用一个二维数组 visited 来记录当前坐标是否已经被访问过 代码 class Solution { public List<Integer> spiralOrder(int[][] matrix) { int m = mat原创 2021-04-24 08:31:01 · 114 阅读 · 0 评论