当前位置:网站首页>Metaapp development interview questions
Metaapp development interview questions
2022-07-23 13:29:00 【Staring foreshadowing】
1. Binary tree , The first line is from left to right The second line is from right to left
leetcode: Power button
1. Special case handling : When the root node of the tree is empty , The empty list is returned directly [] ;
2. initialization : Print results empty list res , Double ended queue with root node deque ;
3.BFS loop : When deque Jump out when empty ;
New list tmp , Used to temporarily store the print results of the current layer ;
Current layer print cycle : The number of cycles is the number of nodes in the current layer ( namely deque length );
Out of the team : The first element out of the team , Write it down as node;
Print : If it is an odd number of layers , take node.val Added to the tmp The tail ; otherwise , Added to the tmp Head ;
Add child nodes : if node Left of ( Right ) The child node is not empty , Join in deque ;
Results the current layer tmp Turn into list And add res ;
Return value : Return to the list of print results res that will do ;
class Solution:
def levelOrder(self, root: TreeNode) -> List[List[int]]:
if not root: return []
res, deque = [], collections.deque([root])
while deque:
tmp = collections.deque()
for _ in range(len(deque)):
node = deque.popleft()
if len(res) % 2: tmp.appendleft(node.val) # Even layers -> Queue header
else: tmp.append(node.val) # Odd number layer -> Queue tail
if node.left: deque.append(node.left)
if node.right: deque.append(node.right)
res.append(list(tmp))
return res
2. List flip :
LeetCode: Power button
Double pointer : Consider traversing the linked list , And modify when accessing each node next Reference point
class Solution:
def reverseList(self, head: ListNode) -> ListNode:
pre, cur = None, head
while cur:
tmp = cur.next # Staging the next node
cur.next = pre # change cur Of next Point to
pre = cur # pre Point to cur The location of
cur = tmp # cur Point to next node
return pre边栏推荐
- 倍福PLC和C#通过ADS通信传输bool类型变量
- Bit synchronization process of CAN controller
- Jupyter notebook add existing virtual environment
- 编译与预处理
- 太空射击 Part 1: 玩家精灵和控制
- "100 Android interview questions" I brushed angrily for Dachang
- Communicate 11 tips for poor performance 
- 软件测试岗位饱和了?自动化测试是新一代‘offer’技能
- Space shooting Part 2-3: dealing with the collision between bullets and the enemy
- 行业现状令人失望,工作之后我又回到UC伯克利读博了
猜你喜欢

当输入网址后,到网页显示,期间发生了什么

Opencv image processing (medium) image smoothing + histogram

C language - big end storage and small end storage

Beifu PLC and C transmit int type variables through ads communication

Convert the specified seconds to minutes and seconds

"100 Android interview questions" I brushed angrily for Dachang

射击 第 1-3 课:图像精灵

MySQL----复合查询 外连接

kubernetes 的这几种存储卷,别再傻傻分不清了

倍福PLC和C#通过ADS通信传输int类型变量
随机推荐
Charles' bag grabbing tool test practice
[jzof] 07 rebuild binary tree
Signal integrity (SI) power integrity (PI) learning notes (XXXI) power distribution network (III)
Day 12 notes
Uncaught (in promise) Neo4jError: WebSocket connection failure. Due to security constraints in your
Compilation and preprocessing
【JZOF】11旋转数组的最小数字
太空射击 Part 1: 玩家精灵和控制
MySQL的索引事务&&JDBC编程
Numpy: quick start to basic operations
PKU doctor's little sister: sharing dry goods at the bottom of the box | five tips to improve learning efficiency
倍福PLC和C#通过ADS通信传输Bool数组变量
Notes on the seventh day
Charles抓包工具测试实战
Jenkins continuous integration error stderr: fatal: unsafe repository ('/home/water/water' is owned by someone else)
Knowledge map: basic concepts
Day 8 notes
Talk about study and work -- Qian Xuesen
How to prevent repeated payment of orders?
当输入网址后,到网页显示,期间发生了什么