Solutions to high-frequency interview questions of LeetCode in C++17, taking into account both efficiency and comprehensibility.
class Solution {
public:
Node* connect(Node* root) {
if (!root) {
return nullptr;
}
if (root->left) {
root->left->next = root->right;
if (root->next) root->right->next = root->next->left;
}
connect(root->left);
connect(root->right);
return root;
}
};