LeetCode 116. Populating Next Right Pointers in Each Node — JavaScript

var connect = function(root) {
let temp = root;
while (temp && temp.left) {
const next = temp.left;
while (temp) {
temp.left.next = temp.right;
temp.right.next = temp.next && temp.next.left;
temp = temp.next
temp = next;
return root;




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store

自學寫程式,目前爲 React 前端工程師。熱愛旅遊,將近 30 個國家,足跡遍佈亞洲與歐洲。生命與街舞已經離不開,歡迎訂閱 Youtube 頻道:https://www.youtube.com/channel/UCEU-bEDl7R-iGyLVZFae33g