题目连接
https://leetcode.com/problems/flatten-binary-tree-to-linked-list/
Flatten Binary Tree to Linked List
Description
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: void flatten(TreeNode* root) { if (!root) return; flatten(root->left); flatten(root->right); if (root->left) { TreeNode* right = root->right; root->right = root->left; root->left = NULL; while (root->right) root = root->right; root->right = right; } } };