javascript 打发时间

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 打发时间相关的知识,希望对你有一定的参考价值。

//      100
//     /    \
//    10     9
//   /  \     \
//  4    5     7
//         \
//          3
//
//expected answer for 3 levels: 110
//expected answer for 4 levels: 115

class Node {
  constructor(time, children) {
    this.time = time;
    this.children = children;
  }
}

const getPassTime = function (employee) {
  let time = employee.time;
  let childTimes = [];
  //console.log("time", time);
  if (employee.children === null) {
    return 0;
  }

  for (child of employee.children) {
    childTimes.push(getPassTime(child));
  }
  
  //console.log("child times", childTimes);
  //console.log("max child time", Math.max(...childTimes));
  return time + Math.max(...childTimes);
}

let e2_1 = new Node(4, null);
let e2_2 = new Node(5, null);
let e2_3 = new Node(7, null);

let e1_1 = new Node(10, [e2_1, e2_2]);
let e1_2 = new Node(9, [e2_3]);

let ceo = new Node(100, [e1_1, e1_2]);

console.log("Pass time", "expected:", 110, "got:", getPassTime(ceo), getPassTime(ceo) === 110);

let e3_1 = new Node(3, null);
e2_1 = new Node(4, null);
e2_2 = new Node(5, [e3_1]);
e2_3 = new Node(7, null);

e1_1 = new Node(10, [e2_1, e2_2]);
e1_2 = new Node(9, [e2_3]);

ceo = new Node(100, [e1_1, e1_2]);
console.log("Pass time", "expected:", 115, "got:", getPassTime(ceo), getPassTime(ceo) === 115);

以上是关于javascript 打发时间的主要内容,如果未能解决你的问题,请参考以下文章

打发时间

打发打发

随便写写,就当是打发时间

上班无聊,自己用python做个小游戏来打发时间

科研之余大家都干什么打发时间?

springboot templates 下的HTML访问不到