二叉树如上图所示,它的输入形式如下:
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));
网友评论