Make a little progress every day , It's already great , Insist on , Don't be too tired , Refuse to roll in , Start with practice every day , Ten minutes a day , Live happily all your life ! The epidemic is still repeated , Everyone wear masks ~ Continue to continue , Come on , Today and Brother cheshen Work together to improve your Python Programming and Interview ability Well , brush ladder on high buildings ~
Put on what I took Photo Well !
Recommend a song every day : Maple ——Jay Chou
The following is my Ladder integral rule :
At least one question a day : An integral +10 branch
If you do one more question ( Or one more way to answer ), Then the points of the day +20 branch (+10+10)
If you do more than three , Start with question 3 +20 branch ( Such as : If you do three questions, you will score -10+10+20=40; If you do four questions, you will score –10+10+20+20=60)Initial classification 100 branch
If you haven't done the problem for one day , Then deduct points -10 branch ( Saturday 、 Except Sunday : rest )
insist !!!
Give you a binary tree , Please return to its button Sequence traversal The resulting node value . ( That is, layer by layer , Access all nodes from left to right ).
Example :
Binary tree :[3,9,20,null,null,15,7],
Return its sequence traversal result :
analysis :
Returns an array of , We also need to initialize the array , But I don't know the size of the array , So it's usually stored in list And then convert it into an array , return list It's simpler .
Borrow the big guy's picture again , That's perfect !
class Solution: def levelOrder(self, root: TreeNode) -> List[List[int]]: if not root: return [] queue = [root] res = [] while queue: n = len(queue) sub_list = [] for i in range(n): node = queue.pop(0) sub_list.append(node.val) if node.left: queue.append(node.left) if node.right: queue.append(node.right) res.append(sub_list) return res
The result is right , Today is also a tiring day , Come here first , Resting !~
Share today , Yongge ( Maybe it's kind to call it this way ) Finally, let's say our best wishes !~
author : Power button (LeetCode)
link :https://leetcode-cn.com/leetbook/read/top-interview-questions-easy/xnarn7/
source : Power button (LeetCode)
author : Data structures and algorithms
link :https://leetcode-cn.com/leetbook/read/top-interview-questions-easy/xnd69e/?discussion=1Pu6Hw
source : Power button (LeetCode)
Score today :+10
Total score :710come on. !!!
項目介紹隨著信息技術和網絡技術的飛速發展,人類已進入全新信息