114. Flatten Binary Tree to Linked List

題目要求根據中序遍歷,將樹的左節點全部移到右節點。 思路:在節點處,判斷是否存在左子節點,若存在,則將左子節點拉伸並連接到右子節點之間。 代碼: TreeNode *getTail(TreeNode *head) //獲得鏈表末尾 { while(head->right) { head=head->right; } return head; }
相關文章
相關標籤/搜索