25道常见算法面试题.pdfVIP

  • 1
  • 0
  • 约5.63千字
  • 约 8页
  • 2019-11-05 发布于江苏
  • 举报
Problem 1 : Is it a loop ? (判断链表是否有环?) Assume that wehave a head pointer to a link-list. Also assumethat we know the list is single-linked. Can you come up an algorithm to checkwhether this link list includes a loop by using O(n) time and O(1) space wheren is the length of the list? Furthermore, can you do so with O(n) time and onlyone register? 方法:使用两个指针,从头开始,一个一次前进一个节点,一个前进 2 个节点, 则最多 2N ,后两个指针可以重合;如果无环,则正常停止。 同样的,可以找到链表的中间节点。同上。 Problem 2 :设计一个复杂度为 n 的算法找到链表倒数第 m 个元素。最后一个 元素假定是倒数第 0 个。 提示:双指针查找 Problem 3

文档评论(0)

1亿VIP精品文档

相关文档