Loop List
Loop List is very common in interview. This article we give a more strict short statement about its solving.
One method to check if there's a loop in a list is to use two speed pointers. But most of articles did not give a proof.
Assume we have a list:
ListNode* head;
Then, we set two pointers start from the head, and one pointer added by 1 step, the other added by 2 steps:
ListNode* p1 = head, *p2 = head;
...
p1 = (p1 -> next) -> next;
p2 = p2 -> next;
Now, we need to proof that, if there's a loop in the list, p1 will meet p2.
- p1 obviously will exceed p2.
- As p1 can only added two steps every time, there're only two relative positions between p1 and p2.
- p1 just before p2. Then as p1 updates first, p2 updates second, they'll meet.
- There's a node between p1 and p2. As p1 updates first, they'll meet.
Loop List的更多相关文章
- Atitit 解决Unhandled event loop exception错误的办法
Atitit 解决Unhandled event loop exception错误的办法 查看workspace/.metadata/.log org.eclipse.swt.SWTError: No ...
- Looper.prepare()和Looper.loop()
什么时候需要 Looper Looper用于封装了android线程中的消息循环,默认情况下一个线程是不存在消息循环(message loop)的,需要调用Looper.prepare()来给线程创建 ...
- PostgreSQL-PL/pgSQL-cursor,loop
将spam_keyword表word字段的字符全部拆分,只是利用过程语言完成循环的操作而已. create or replace function proc1() returns setof text ...
- archlinux 加载loop模块,且设定loop设备个数
如果loop模块没有编译进内核就要先加载loop模块 modprobe loop 然后更改/etc/modprobe.d/modprobe.conf(有些文章写是在/etc/modprobe.conf ...
- 工作邮件loop的用法
examples come from native speaker Put john in the loop about this. He will have good advice. Why hav ...
- VMWare虚拟机实例拷贝到另一台服务器后出现Error in the RPC receive loop: RpcIn: Unable to send.错误的解决
把一个VMWare虚拟机实例拷贝到另一台服务器后,在事件查看器中的应用程序日志中不断出现Error in the RPC receive loop: RpcIn: Unable to send.错误, ...
- 禁用nested loop join里的spool
禁用nested loop join里的spool 转载自: https://blogs.msdn.microsoft.com/psssql/2015/12/15/spool-operator-and ...
- Android Handler、Loop 的简单使用
1.子线程和子线程之间的通信 package lib.com.myapplication; import android.os.Bundle; import android.os.Handler; i ...
- mysql while,loop,repeat循环,符合条件跳出循环
1.while循环 DELIMITER $$ DROP PROCEDURE IF EXISTS `sp_test_while`$$ CREATE PROCEDURE `sp_test_while`( ...
- 1122MySQL性能优化之 Nested Loop Join和Block Nested-Loop Join(BNL)
转自http://blog.itpub.net/22664653/viewspace-1692317/ 一 介绍 相信许多开发/DBA在使用MySQL的过程中,对于MySQL处理多表关联的方式或者说 ...
随机推荐
- 基于centos6.5 hadoop 伪分布式安装
步骤1:修改IP 地址和主机名: vi /etc/sysconfig/network-scripts/ifcfg-eth0 如果该文件打开为空白文件代表你计算机上的网卡文件不是这个名称“ifcfg-e ...
- mysql 压缩版安装
环境介绍:win2008_x64+mysql5.7.10 64位 1.将压缩包解压到d:\\mysql目录,并将mysql目录中的my-default.ini 重命名为my.ini 2.将my.in ...
- IOS初级:NSUserDefaults
NSUserDefaults(偏好设置),一个APP对应一个偏好设置 保存/新增数据 //存储数据 NSUserDefaults *defaults = [NSUserDefaults standar ...
- js 异步加载和同步加载
异步加载 异步加载也叫非阻塞模式加载,浏览器在下载js的同时,同时还会执行后续的页面处理.在script标签内,用js创建一个script元素并插入到document中,这种就是异步加载js文件了: ...
- Mercurial和Git的主要区别(zz)
Mercurial和Git的主要区别 17 August 2008 1.Mercurial用Python开发,Git用C开发,相对来说,Git比较快,但是Mercurial的性能也不差 2.Mercu ...
- mybatis分页插件Mybatis_PageHelper 简单案例
源码地址(官网,文档) 使用条件: 支持mybatis 3.1.0+ sql 解析工具(jsqlparser.jar) 下载 Mybatis_PageHelper 版本随意,反正我用的5.0.0 m ...
- 2018.10.25 洛谷P4187 [USACO18JAN]Stamp Painting(计数dp)
传送门 其实本来想做组合数学的2333. 谁知道是道dpdpdp. 唉只能顺手做了 还是用真难则反的思想. 这题我们倒着考虑,只需要求出不合法方案数就行了. 这个显然是随便dpdpdp的. f[i]f ...
- select 选中是否包含
$("#regionname1").find("option:contains('"+regionname+"')").prop(" ...
- 关于Cell中的各种值的类型判断
switch (cell.getCellType()){ case Cell.CELL_TYPE_NUMERIC: //数字 cellValue = stringDateProcess(cell); ...
- Codeforces Round #543 (Div. 2) D 双指针 + 模拟
https://codeforces.com/contest/1121/problem/D 题意 给你一个m(<=5e5)个数的序列,选择删除某些数,使得剩下的数按每组k个数以此分成n组(n*k ...