美文网首页
二叉树相关

二叉树相关

作者: RQrry | 来源:发表于2019-09-24 23:23 被阅读0次
二叉树

二叉树如上图所示,它的输入形式如下:

input: 1(2(3,4(,5)),6(7,))

输出中序遍历的结果:

output: 3245176
let input = '1(2(3,4(,5)),6(7,))';

function solution(input) {
  let reg = /(\d*)\((\d*)\,(\d*)\)/;
  while (input.match(reg)) {
    input = input.replace(reg, function ($, $1, $2, $3) {
      return $2+$1+$3;
    })
  }
  return input;
}

console.log(solution(input));

相关文章

网友评论

      本文标题:二叉树相关

      本文链接:https://www.haomeiwen.com/subject/jrteyctx.html