Obtain forest out of tree with even number of nodes

后端 未结 8 511
别跟我提以往
别跟我提以往 2021-02-03 20:31

I\'m stuck on a code challenge, and I want a hint.

PROBLEM: You are given a tree data structure (without cycles) and are asked to remo

8条回答
  •  心在旅途
    2021-02-03 21:36

    This is my solution. I didn't use bfs tree, just allocated another array for holding eachnode's and their children nodes total number.

    import java.util.Scanner;
    import java.util.Arrays;
    
    public class Solution {
            public static void main(String[] args) {
                    int tree[];
                    int count[];
    
                    Scanner scan = new Scanner(System.in);
    
                    int N = scan.nextInt(); //points
                    int M = scan.nextInt();
    
                    tree = new int[N];
                    count = new int[N];
                    Arrays.fill(count, 1);
    
                    for(int i=0;i

提交回复
热议问题