问题
问答题 简答题
给两个变量,如何找出一个带环单链表中是什么地方出现环的?
答案
参考答案:
一个递增一,一个递增二,他们指向同一个接点时就是环内的一个点,记做p1。设递增1的走了N步,递增2的走了2N步。p2指向链表头。则p1,p2同时走N步还在p1点相遇。第一次相遇的点就是出现环的节点。
给两个变量,如何找出一个带环单链表中是什么地方出现环的?
参考答案:
一个递增一,一个递增二,他们指向同一个接点时就是环内的一个点,记做p1。设递增1的走了N步,递增2的走了2N步。p2指向链表头。则p1,p2同时走N步还在p1点相遇。第一次相遇的点就是出现环的节点。
Dear Bill, How are you? It’s very nice 36 you to write to me. Let me 37 something about my life in China. I think you 38 to know it. I live in Li Lei’s home. He is my 39. His father and mother are both teachers. Their house isn’t big. 40 of them are very friendly 41 me. They teach me Chinese 42 I teach them English. Now I 43 with them in Chinese. But I can’t 44 very well. Chinese is very 45 to learn, I think. Mrs Li often teaches me how to 46 Chinese food. Hmm! How much I like Chinese food! My school is not far. I go to school by bike. I 47 six classes every day. 48 I play games with my classmates. I have a good 49 here. Don’t you want to come? Please write 50 soon. Love from Jim.
|