We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
funclevelOrder(root:Node?)->Void{guardletroot=rootelse{return}varresult:[Int]=[]varqueue:[Node]=[]queue.append(root)while!queue.isEmpty{letnode=queue.removeFirst()ifletleft=node.left{queue.append(left)}ifletright=node.right{queue.append(right)}result.append(node.data)}print(result.map{String($0)}.joined(separator:" "))// Complete the function}// End of levelOrder function
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 23: BST Level-Order Traversal
You are viewing a single comment's thread. Return to all comments →
swift solution