学无先后,达者为师

网站首页 java综合 正文

剑指Offer之Java算法习题精讲排列与N叉树_java

作者:明天一定.   更新时间: 2022-05-21 java综合

题目一

 解法

class Solution {
    LinkedList> ans = new LinkedList>();
    public List> permute(int[] nums) {
        LinkedList list = new LinkedList();
        boolean[] bo = new boolean[nums.length];
        method(nums,bo,list);
        return ans;
    }
    public void method(int[] nums,boolean[] bo ,LinkedList list){
        if(list.size()==nums.length){
            ans.add(new LinkedList(list));
            return;
        }
        for(int i = 0;i

题目二

 解法

/*
// Definition for a Node.
class Node {
    public int val;
    public List children;
    public Node() {}
    public Node(int _val) {
        val = _val;
    }
    public Node(int _val, List _children) {
        val = _val;
        children = _children;
    }
};
*/
 
class Solution {
    public int maxDepth(Node root) {
        if(root==null){
            return 0;
        }
        int maxChildDepth = 0;
        for(int i = 0;i

原文链接:https://blog.csdn.net/wai_58934/article/details/123407928

栏目分类
最近更新