114. Flatten Binary Tree to Linked List 發表於 2023-02-13 | 分類於 leetcode problemsolution123456789101112131415161718class Solution {public: void flatten(TreeNode* root) { if(!root) return; flatten(root->left); flatten(root->right); TreeNode * temp = root->right; root->right = root->left; root->left = nullptr; TreeNode *p = root; while(p->right) p=p->right; p->right = temp; }}; analysis time complexity O(n) space complexity O(1)