-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path116.cpp
More file actions
33 lines (32 loc) · 768 Bytes
/
116.cpp
File metadata and controls
33 lines (32 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//
// 116.cpp
// leetcode
//
// Created by R Z on 2018/8/9.
// Copyright © 2018年 R Z. All rights reserved.
//
#include <stdio.h>
/**
* Definition for binary tree with next pointer.*/
struct TreeLinkNode {
int val;
TreeLinkNode *left, *right, *next;
TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL) {}
};
class Solution {
public:
void connect(TreeLinkNode *root) {
if(root==NULL) return;
TreeLinkNode* pre=root;
TreeLinkNode* cur=NULL;
while(pre->left){
cur=pre;
while(cur){
cur->left->next=cur->right;
if(cur->next) cur->right->next=cur->next->left;
cur=cur->next;
}
pre=pre->left;
}
}
};