1. 程式人生 > 其它 >vue實現div高度可拖拽

vue實現div高度可拖拽

題目來源:94. 二叉樹的中序遍歷

給定一個二叉樹的根節點root,返回它的中序遍歷。

/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[]}
 
*/ var inorderTraversal = function(root) { if(root == null){ return []; } let cur = root; let res = []; while(cur){ if(cur.left == null){ res.push(cur.val); cur = cur.right; }else{ let node = cur.left; while(node != null
&& node.right != null && node.right != cur){ node = node.right; } if(node.right == null){ node.right = cur; cur = cur.left; }else{ node.right = null; res.push(cur.val) cur
= cur.right } } } return res; };

示例 1:

輸入:root = [1,null,2,3]
輸出:[1,3,2]

示例 2:

輸入:root = []
輸出:[]

示例 3:

輸入:root = [1]
輸出:[1]

示例 4:

輸入:root = [1,2]
輸出:[2,1]

示例 5:

輸入:root = [1,null,2]
輸出:[1,2]

提示:

  • 樹中節點數目在範圍[0, 100]
  • -100 <= Node.val <= 100

進階:遞迴演算法很簡單,你可以通過迭代演算法完成嗎?