-
116. Populating Next Right Pointers in Each NodeLeetCode_Study_Plan/Algorithm 2022. 12. 26. 14:22
https://leetcode.com/problems/populating-next-right-pointers-in-each-node/description/
Populating Next Right Pointers in Each Node - LeetCode
Populating Next Right Pointers in Each Node - You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition: struct Node { int val; Node *left; Node *right; Node
leetcode.com
class Solution { public Node connect(Node root) { connect(root, null); return root; } private void connect(Node root, Node right) { if (root == null) return; root.next = right; connect(root.left, root.right); connect(root.right, right == null? null : root.next.left); } }
'LeetCode_Study_Plan > Algorithm' 카테고리의 다른 글
994. Rotting Oranges java (0) 2022.12.30 🎵542. 01 Matrix java (0) 2022.12.27 🎵 617. Merge Two Binary Trees java (0) 2022.12.26 695. Max Area of Island java (0) 2022.12.22 733. Flood Fill java (0) 2022.12.22