Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c97719e

Browse files
committed
Add solution 116.
1 parent c71d626 commit c97719e

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
// Definition for a Node.
3+
class Node {
4+
public $val;
5+
public $left;
6+
public $right;
7+
public $next;
8+
9+
@param Integer $val
10+
@param Node $left
11+
@param Node $right
12+
@param Node $next
13+
function __construct($val, $left, $right, $next) {
14+
$this->val = $val;
15+
$this->left = $left;
16+
$this->right = $right;
17+
$this->next = $next;
18+
}
19+
}
20+
*/
21+
class Solution {
22+
23+
/**
24+
* @param Node $root
25+
* @return Node
26+
*/
27+
function connect($root) {
28+
if($root==null){
29+
return null;
30+
}
31+
32+
if($root->left!=null && $root->right!=null){
33+
$root->left->next = $root->right;
34+
}
35+
36+
if($root->next!=null && $root->right!=null){
37+
$root->right->next=$root->next->left;
38+
}
39+
40+
self::connect($root->left);
41+
self::connect($root->right);
42+
return $root;
43+
}
44+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /