We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 64a8291 commit abd25e1Copy full SHA for abd25e1
solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/Solution.cpp
@@ -0,0 +1,22 @@
1
+class Solution {
2
+public:
3
+ Node* connect(Node* root) {
4
+ if (!root) return nullptr;
5
+ queue<Node*> q;
6
+ q.push(root);
7
+ while (!q.empty()) {
8
+ int size = q.size();
9
+ for (int i = 0; i < size; ++i) {
10
+ Node* t = q.front();
11
+ q.pop();
12
+ if (i < size - 1) {
13
+ t->next = q.front();
14
+ }
15
+ if (t->left) q.push(t->left);
16
+ if (t->right) q.push(t->right);
17
18
19
+
20
+ return root;
21
22
+};
0 commit comments