首页 > 编程语言 >算法笔记|Day11二叉树

算法笔记|Day11二叉树

时间:2024-07-29 21:53:06浏览次数:18  
标签:deque right TreeNode val int 算法 二叉树 left Day11

算法笔记|Day11二叉树

☆☆☆☆☆leetcode 144.二叉树的前序遍历

题目链接:leetcode 144.二叉树的前序遍历

题目分析

前序遍历是深度优先遍历,分别采用递归方法和迭代方法对二叉树遍历,为了前序、中序、后序三种遍历迭代方法代码逻辑相同增添统一迭代方法。

代码

1.递归遍历
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> preorderTraversal(TreeNode root) {
        List<Integer> res=new ArrayList<>();
        preorder(root,res);
        return res;
    }

    public void preorder(TreeNode root,List<Integer> res){
        if(root==null)
            return;
        res.add(root.val);
        preorder(root.left,res);
        preorder(root.right,res);
    }
}
2.迭代遍历
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> preorderTraversal(TreeNode root) {
        List<Integer> res=new ArrayList<>();
        if(root==null)
            return res;
        Stack<TreeNode> stack=new Stack<>();
        stack.push(root);
        while(!stack.isEmpty()){
            TreeNode node=stack.pop();
            res.add(node.val);
            if(node.right!=null)
                stack.push(node.right);
            if(node.left!=null)
                stack.push(node.left);
        }
        return res;
    }
}
3.统一迭代遍历
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> preorderTraversal(TreeNode root) {
        List<Integer>res=new ArrayList<>();
        Stack<TreeNode> stack=new Stack<>();
        if(root!=null)
            stack.push(root);
        while(!stack.isEmpty()){
            TreeNode node=stack.peek();
            if(node!=null){
                stack.pop();
                if(node.right!=null)
                    stack.push(node.right);
                if(node.left!=null)
                    stack.push(node.left);
                stack.push(node);
                stack.push(null);             
            }else{
                stack.pop();
                node=stack.peek();
                stack.pop();
                res.add(node.val);
            }
        }
        return res;
    }
}

☆☆☆☆☆leetcode 94.二叉树的中序遍历

题目链接:leetcode 94.二叉树的中序遍历

题目分析

中序遍历是深度优先遍历,分别采用递归方法和迭代方法对二叉树遍历,为了前序、中序、后序三种遍历迭代方法代码逻辑相同增添统一迭代方法。

代码

1.递归遍历
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res=new ArrayList<>();
        inorder(root,res);
        return res;
    }

    public void inorder(TreeNode root,List<Integer> res){
        if(root==null)
            return;
        inorder(root.left,res);
        res.add(root.val);
        inorder(root.right,res);
    }
}
2.迭代遍历
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res=new ArrayList<>();
        if(root==null)
            return res;
        Stack<TreeNode> stack=new Stack<>();
        TreeNode cur=root;
        while(cur!=null||!stack.isEmpty()){
            if(cur!=null){
                stack.push(cur);
                cur=cur.left;
            }else{
                cur=stack.pop();
                res.add(cur.val);
                cur=cur.right;
            }
        }
        return res;
    }
}
3.统一迭代遍历
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer>res=new ArrayList<>();
        Stack<TreeNode> stack=new Stack<>();
        if(root!=null)
            stack.push(root);
        while(!stack.isEmpty()){
            TreeNode node=stack.peek();
            if(node!=null){
                stack.pop();
                if(node.right!=null)
                    stack.push(node.right);
                stack.push(node);
                stack.push(null);
                if(node.left!=null)
                    stack.push(node.left);
            }else{
                stack.pop();
                node=stack.peek();
                stack.pop();
                res.add(node.val);
            }
        }
        return res;   
    }
}

☆☆☆☆☆leetcode 145.二叉树的后序遍历

题目链接:leetcode 145.二叉树的后序遍历

题目分析

后序遍历是深度优先遍历,分别采用递归方法和迭代方法对二叉树遍历,为了前序、中序、后序三种遍历迭代方法代码逻辑相同增添统一迭代方法。

代码

1.递归遍历
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> res=new ArrayList<>();
        postorder(root,res);
        return res;
    }

    public void postorder(TreeNode root,List<Integer> res){
        if(root==null)
            return;
        postorder(root.left,res);
        postorder(root.right,res);
        res.add(root.val);
    }
}
2.迭代遍历
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> res=new ArrayList<>();
        if(root==null)
            return res;
        Stack<TreeNode> stack=new Stack<>();
        stack.push(root);
        while(!stack.isEmpty()){
            TreeNode node=stack.pop();
            res.add(node.val);
            if(node.left!=null)
                stack.push(node.left);
            if(node.right!=null)
                stack.push(node.right);
        }
        Collections.reverse(res);
        return res;
    }
}
3.统一迭代遍历
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> postorderTraversal(TreeNode root) {
                List<Integer>res=new ArrayList<>();
        Stack<TreeNode> stack=new Stack<>();
        if(root!=null)
            stack.push(root);
        while(!stack.isEmpty()){
            TreeNode node=stack.peek();
            if(node!=null){
                stack.pop();
                stack.push(node);
                stack.push(null);
                if(node.right!=null)
                    stack.push(node.right);
                if(node.left!=null)
                    stack.push(node.left);
            }else{
                stack.pop();
                node=stack.peek();
                stack.pop();
                res.add(node.val);
            }
        }
        return res;
    }
}

☆☆☆☆☆leetcode 102.二叉树的层序遍历

题目链接:leetcode 102.二叉树的层序遍历

题目分析

层序遍历是广度优先遍历,可以使用队列来实现。

代码

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<List<Integer>> levelOrder(TreeNode root) {
        List<List<Integer>> res=new ArrayList<>();
        Deque<TreeNode> deque=new LinkedList<>();
        if(root==null)
            return res;
        deque.add(root);
        while(!deque.isEmpty()){
            List<Integer> itemList=new ArrayList<>();
            int len=deque.size();
            while(len>0){
                TreeNode tempNode=deque.poll();
                itemList.add(tempNode.val);
                if(tempNode.left!=null)
                    deque.add(tempNode.left);
                if(tempNode.right!=null)
                    deque.add(tempNode.right);
                len--;
            }
            res.add(itemList);
        }
        return res;
    }
}

☆☆☆☆☆leetcode 107.二叉树的层次遍历II

题目链接:leetcode 107.二叉树的层次遍历II

题目分析

需要将结果res数组反转一下,相当于将后面的结果加到list表头。

代码

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<List<Integer>> levelOrderBottom(TreeNode root) {
        List<List<Integer>> res=new ArrayList<>();
        Deque<TreeNode> deque=new LinkedList<>();
        if(root==null)
            return res;
        deque.add(root);
        while(!deque.isEmpty()){
            List<Integer> itemList=new ArrayList<>();
            int len=deque.size();
            while(len>0){
                TreeNode tempNode=deque.poll();
                itemList.add(tempNode.val);
                if(tempNode.left!=null)
                    deque.add(tempNode.left);
                if(tempNode.right!=null)
                    deque.add(tempNode.right);
                len--;
            }
            res.add(0,itemList);
        }
        return res;
    }
}

☆☆☆☆☆leetcode 199.二叉树的右视图

题目链接:leetcode 199.二叉树的右视图

题目分析

层序遍历时,判断是否遍历到单层的最后面的元素,若是放进res数组中。

代码

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> res=new ArrayList<>();
        Deque<TreeNode> deque=new LinkedList<>();
        if(root==null)
            return res;
        deque.add(root);
        while(!deque.isEmpty()){
            List<Integer> itemList=new ArrayList<>();
            int len=deque.size();
            for(int i=0;i<len;i++){
                TreeNode tempNode=deque.poll();
                if(tempNode.left!=null)
                    deque.add(tempNode.left);
                if(tempNode.right!=null)
                    deque.add(tempNode.right);
                if(i==len-1)
                    res.add(tempNode.val);
            }
        }
        return res;
    }
}

☆☆☆☆☆leetcode 637.二叉树的层平均值

题目链接:leetcode 637.二叉树的层平均值

题目分析

层序遍历时,每一层求总和并取均值。

代码

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Double> averageOfLevels(TreeNode root) {
        List<Double> res=new ArrayList<>();
        Deque<TreeNode> deque=new LinkedList<>();
        if(root==null)
            return res;
        deque.add(root);
        while(!deque.isEmpty()){
            int len=deque.size();
            double sum=0;
            for(int i=0;i<len;i++){
                TreeNode tempNode=deque.poll();
                if(tempNode.left!=null)
                    deque.add(tempNode.left);
                if(tempNode.right!=null)
                    deque.add(tempNode.right);
                sum+=tempNode.val; 
            }
            res.add(sum/len);
        }
        return res;
    }
}

☆☆☆☆☆leetcode 429.N叉树的层序遍历

题目链接:leetcode 429.N叉树的层序遍历

题目分析

较二叉树,每个节点有多个子节点。

代码

/*
// Definition for a Node.
class Node {
    public int val;
    public List<Node> children;

    public Node() {}

    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, List<Node> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
    public List<List<Integer>> levelOrder(Node root) {
        List<List<Integer>> res=new ArrayList<>();
        Deque<Node> deque=new LinkedList<>();
        if(root==null)
            return res;
        deque.add(root);
        while(!deque.isEmpty()){
            List<Integer> itemList=new ArrayList<>();
            int len=deque.size();
            for(int i=0;i<len;i++){
                Node tempNode=deque.poll();
                itemList.add(tempNode.val);
                List<Node> children=tempNode.children;
                if(children==null||children.size()==0)
                    continue;
                for(Node child:children)
                    if(child!=null)
                        deque.add(child);
            }
            res.add(itemList);
        }
        return res;
    }
}

☆☆☆☆☆leetcode 515.在每个树行中找最大值

题目链接:leetcode 515.在每个树行中找最大值

题目分析

层序遍历时,每一层求最大值。

代码

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> largestValues(TreeNode root) {
        List<Integer> res=new ArrayList<>();
        Deque<TreeNode> deque=new LinkedList<>();
        if(root==null)
            return res;
        deque.add(root);
        while(!deque.isEmpty()){
            int max=Integer.MIN_VALUE;
            int len=deque.size();
            for(int i=0;i<len;i++){
                TreeNode tempNode=deque.poll();
                if(tempNode.left!=null)
                    deque.add(tempNode.left);
                if(tempNode.right!=null)
                    deque.add(tempNode.right);
                max=Math.max(max,tempNode.val); 
            }
            res.add(max);
        }
        return res;
    }
}

☆☆☆☆☆leetcode 116.填充每个节点的下一个右侧节点指针

题目链接:leetcode 116.填充每个节点的下一个右侧节点指针

题目分析

层序遍历时,让前一个节点指向本节点。

代码

/*
// Definition for a Node.
class Node {
    public int val;
    public Node left;
    public Node right;
    public Node next;

    public Node() {}
    
    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, Node _left, Node _right, Node _next) {
        val = _val;
        left = _left;
        right = _right;
        next = _next;
    }
};
*/

class Solution {
    public Node connect(Node root) {
        Deque<Node> deque=new LinkedList<>();
        if(root!=null)
            deque.add(root);
        while(!deque.isEmpty()){
            int len=deque.size();
            Node cur=deque.poll();
            if(cur.left!=null)
                deque.add(cur.left);
            if(cur.right!=null)
                deque.add(cur.right);
            for(int i=1;i<len;i++){
                Node next=deque.poll();
                if(next.left!=null)
                    deque.add(next.left);
                if(next.right!=null)
                    deque.add(next.right);
                cur.next=next;
                cur=next;
            }
        }
        return root;  
    }
}

☆☆☆☆☆leetcode 117.填充每个节点的下一个右侧节点指针II

题目链接:leetcode 117.填充每个节点的下一个右侧节点指针II

题目分析

层序遍历时,让前一个节点指向本节点,但此题不一定为完全二叉树。

代码

/*
// Definition for a Node.
class Node {
    public int val;
    public Node left;
    public Node right;
    public Node next;

    public Node() {}
    
    public Node(int _val) {
        val = _val;
    }

    public Node(int _val, Node _left, Node _right, Node _next) {
        val = _val;
        left = _left;
        right = _right;
        next = _next;
    }
};
*/

class Solution {
    public Node connect(Node root) {
        Deque<Node> deque=new LinkedList<>();
        if(root!=null)
            deque.add(root);
        while(!deque.isEmpty()){
            int len=deque.size();
            Node node=null;
            Node nodePre=null;
            for(int i=0;i<len;i++){
                if(i==0){
                    nodePre=deque.poll();
                    node=nodePre;
                }else{
                    node=deque.poll();
                    nodePre.next=node;
                    nodePre=nodePre.next;
                }
                if(node.left!=null)
                    deque.add(node.left);
                if(node.right!=null)
                    deque.add(node.right);
            }
        }
        return root;  
    }
}

☆☆☆☆☆leetcode 104.二叉树的最大深度

题目链接:leetcode 104.二叉树的最大深度

题目分析

层序遍历,输出热水数组的大小即可。

代码

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int maxDepth(TreeNode root) {
        List<List<Integer>> res=new ArrayList<>();
        Deque<TreeNode> deque=new LinkedList<>();
        if(root==null)
            return 0;
        deque.add(root);
        while(!deque.isEmpty()){
            List<Integer> itemList=new ArrayList<>();
            int len=deque.size();
            while(len>0){
                TreeNode tempNode=deque.poll();
                itemList.add(tempNode.val);
                if(tempNode.left!=null)
                    deque.add(tempNode.left);
                if(tempNode.right!=null)
                    deque.add(tempNode.right);
                len--;
            }
            res.add(itemList);
        }
        return res.size();
    }
}

☆☆☆☆☆leetcode 111.二叉树的最小深度

题目链接:leetcode 111.二叉树的最小深度

题目分析

层序遍历,当某个节点的左右子节点均为null,返回最小深度。

代码

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int minDepth(TreeNode root) {
                List<List<Integer>> res=new ArrayList<>();
        Deque<TreeNode> deque=new LinkedList<>();
        if(root==null)
            return 0;
        deque.add(root);
        int depth=0;
        while(!deque.isEmpty()){
            List<Integer> itemList=new ArrayList<>();
            int len=deque.size();
            depth++;
            while(len>0){
                TreeNode tempNode=deque.poll();
                itemList.add(tempNode.val);
                if(tempNode.left==null&&tempNode.right==null)
                    return depth;
                if(tempNode.left!=null)
                    deque.add(tempNode.left);
                if(tempNode.right!=null)
                    deque.add(tempNode.right);
                len--;
            }
            res.add(itemList);
        }
        return depth;
    }
}

标签:deque,right,TreeNode,val,int,算法,二叉树,left,Day11
From: https://blog.csdn.net/m0_57632621/article/details/140781022

相关文章

  • 2024“钉耙编程”中国大学生算法设计超级联赛(2)
    女神的睿智voidsolve(){strings;cin>>s;inta=0,b=0;for(inti=0;i<s.size();++i){if(s[i]==s[0])a++;if(s[i]==s[4])b++;}if(s[0]==s[4])cout<<s[0]<<'\n'......
  • ICEEMDAN算法 python代码实现
    1.安装matlab.enginepython库里没有ICEEMDAN的方法,需要通过python调用matlab的库中的ICEEMDAN。首先下载python和matlab(这里就不过多阐述了),python和matlab的版本要对应,下面是python和matlab对应的版本(仅供参考)(要记住matlab安装的位置,下面要用)从anacondapropmt进入自己创建......
  • KMP1(字符串基本概念,KMP算法和简单应用)
    KMP1(字符串基本概念,KMP算法和简单应用)基础定义字符串\(S\):无特殊说明,字符串仅由26个小写字母\('a'-'z'\)构成,并用大写字母表示一个字符串。\(|S|\):表示一个字符串的长度\(S[i]\):表示字符串\(S\)第\(i\)个位置的字母,下标从\(1\)开始。子串\(S[l,r]\):表示......
  • Day 27 贪心算法 Part01
    455.分发饼干思路:既然要满足最多的小孩吃到饼干,那么肯定优先满足胃口小的更能满足最多的。因此,先对两个数组排序。每次选择最小的能满足当前孩子的饼干。classSolution{publicintfindContentChildren(int[]g,int[]s){Arrays.sort(g);Arrays.sor......
  • LeetCode - #107 二叉树的层序遍历 II
    文章目录前言1.描述2.示例3.答案关于我们前言我们社区陆续会将顾毅(Netflix增长黑客,《iOS面试之道》作者,ACE职业健身教练。)的Swift算法题题解整理为文字版以方便大家学习与阅读。LeetCode算法到目前我们已经更新到105期,我们会保持更新时间和进度(周一、......
  • 可变阶数高斯消元算法-passcal-c shap-c语言
    高斯消元法在各种工程领域都有广泛的应用,尤其是在需要求解线性方程组的情况下。尽管高斯消元法在某些情况下可能不是最高效的算法,但它仍然是一个强大且通用的工具,对于许多工程问题来说是非常实用的。随着计算机性能的提高,高斯消元法在处理大规模问题时也变得更加可行。高斯消......
  • Tarjan 算法及连通性问题
    无向图的连通性dfs树dfs树上存在树边和返祖边,不存在横叉边。割点若一点\(u\)是割点,那么必定存在一个儿子,删去\(u\)后和他的父亲不连通。如果不存在,和\(u\)相连的所有点依然联通,那么连通性不变,不是割点。若是根节点,若有至少\(2\)个儿子那么就是割点。判断一个点不......
  • 2024“钉耙编程”中国大学生算法设计超级联赛(4)
    Preface最唐氏的一集,有人写03一直过不去红温了然后白兰了一整场,怎么回事呢最后很可惜06因为多维数组调用时顺序出了点问题,导致cache爆了然后常数太大TLE了,但凡时间延长1min都改完过了由于今天过的题少就只写过了的六个题,剩下时间还要写昨晚CF的博客最优K子段......
  • DAY13 二叉树part01
     今日任务 二叉树的递归遍历(前中后)二叉树的迭代遍历(前中后)二叉树的统一迭代遍历二叉树的层序遍历(共十道题目)完成情况递归已掌握,代码略迭代前中手写一编,后和统一未学习层序遍历题目如下102.二叉树的层序遍历1/**2*Definitionforabinarytreenode.3*s......
  • 华为OD笔试机试 - 园区参观路径 (Java 2024年C卷D卷真题算法)
    华为OD机试(C卷+D卷)2024真题目录(Java&c++&python)题目描述园区某部门举办了FamilyDay,邀请员工及其家属参加;将公司园区视为一个矩形,起始园区设置在左上角,终点园区设置在右下角;家属参观园区时,只能向右和向下园区前进,求从起始园区到终点园区会有多少条不同的参观路径......