第 07 天 不断尝试直到成功( leetcode 106 )

JavaScript 解答

var buildTree = function(inorder, postorder) {
  if (!inorder.length || !postorder.length) {
    return null
  }
  let rootVal = postorder[postorder.length - 1]
  let root = new TreeNode(rootVal)
  let k = inorder.indexOf(rootVal)
  root.left = buildTree(inorder.slice(0, k), postorder.slice(0, k))
  root.right = buildTree(inorder.slice(k+1), postorder.slice(k, postorder.length - 1))
  return root
};

Ruby 解答

def build_tree(inorder, postorder)
    length=postorder.length
    if length==0
        return nil
    end
    root=TreeNode.new(postorder[length-1])
    mid=0
    while inorder[mid]!=postorder[length-1]
        mid+=1
    end
    root.left=build_tree(inorder[0...mid],postorder[0...mid])
    root.right=build_tree(inorder[mid+1...inorder.length],postorder[mid...length-1])
    return root
end

<<:  EP 15: The Button of item in ListView binds Command to ViewModel

>>:  Day08-gitlab job 的工作流

@Day25 | C# WixToolset + WPF 帅到不行的安装包 [既有的自订栏位介接]

搞定好 画面了以後,现在要把既有的自订栏位给加进去, 先用"选择路径"的自订栏位...

Mikrotik RouterOS从入门到实战系列-Mikrotik入门第三课

Mikrotik RouterOS从入门到实战系列-Mikrotik入门第三课 CAPsMAN无线控...

Day 30:完赛感言

Keyword: 哇终於到了这天,30天的铁人赛没想到我居然能够撑完. 当初选择KMM的原因主要是听...

30天学会C语言: Day 8-无限执行篇

指派/指定 运算子(Assignment Operator) 可以用来设定变数值的运算子,前面用过的...

Day6 CSS 是做什麽用的?

在大致了解了几个常用的HTML元素之後,或许会有以下的困惑? 网页上的文字颜色有各种颜色,为什麽自...