写点什么

Week 8 作業

用户头像
Christy LAW
关注
发布于: 2020 年 11 月 21 日
1) 有两个单向链表(链表长度分别为 m,n),这两个单向链表有可能在某个元素合并,也可能不合并,如下图所示的这样。现在给定两个链表的头指针,在不修改链表的情况下,如何快速地判断这两个链表是否合并?如果合并,找到合并的元素,也就是图中的 x 元素。


请用代码(或伪代码)描述算法,并给出时间复杂度。



public ListNode getIntersectionNode(ListNode headA, ListNode headB) {  //boundary check  if(headA == null || headB == null) return null;
ListNode a = headA; ListNode b = headB;
//if a & b have different len, then we will stop the loop after second iteration while (a != b){ //for the end of first iteration, we just reset the pointer to the head of another linkedlist a = a == null? headB : a.next; b = b == null? headA : b.next; }
return a;}
复制代码


Time complexity: O(m+n)

Space complexity: O(1)


2) 请画出 DataNode 服务器节点宕机的时候,HDFS 的处理过程时序图。

(有時間才做)


发布于: 2020 年 11 月 21 日阅读数: 27
用户头像

Christy LAW

关注

Christy | Software Engineer 2020.03.19 加入

Github : https://github.com/christypacc21

评论

发布
暂无评论
Week 8 作業