File tree Expand file tree Collapse file tree
main/java/com/crossoverjie/algorithm
test/java/com/crossoverjie/algorithm Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ public boolean isLoop(Node node){
3737 return true ;
3838 }
3939
40+ if (fast .next == null ){
41+ return false ;
42+ }
4043 //slow走慢点 fast走快点
4144 slow = slow .next ;
4245 fast = fast .next .next ;
Original file line number Diff line number Diff line change @@ -42,4 +42,21 @@ public void isLoop2() throws Exception {
4242 Assert .assertEquals (loop ,true );
4343 }
4444
45+ /**
46+ * 无环
47+ * @throws Exception
48+ */
49+ @ Test
50+ public void isLoop3 () throws Exception {
51+ LinkLoop .Node node2 = new LinkLoop .Node ("2" ) ;
52+ LinkLoop .Node node1 = new LinkLoop .Node ("1" ) ;
53+
54+ node1 .next = node2 ;
55+
56+
57+ LinkLoop linkLoop = new LinkLoop () ;
58+ boolean loop = linkLoop .isLoop (node1 );
59+ Assert .assertEquals (loop ,false );
60+ }
61+
4562}
You can’t perform that action at this time.
0 commit comments