Skip to content

Latest commit

 

History

History
83 lines (63 loc) · 1.06 KB

[0114] 二叉树展开为链表.md

File metadata and controls

83 lines (63 loc) · 1.06 KB
title tags categories author comments updated permalink mathjax top description date
[0114] 二叉树展开为链表
leetcode
leetcode
张学志
true
false
false
false
...
2019-12-31 16:01:54 -0800

题目描述

给定一个二叉树,原地将它展开为链表。

例如,给定二叉树

    1
   / \
  2   5
 / \   \
3   4   6

将其展开为:

1
 \
  2
   \
    3
     \
      4
       \
        5
         \
          6
Related Topics
  • 深度优先搜索
  • 题目代码

    /**
     * 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) {
    
        }
    };

    题目解析

    方法一

    方法二

    方法三