Skip to content

Commit 776ae2e

Browse files
committed
💡 Documenting source code.
1 parent e5bee08 commit 776ae2e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README-ZH.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ assertEqual(xx.getAge(), 110);
121121
## 函数
122122

123123
```js
124+
// 判断链表是否有环
124125
bool hasCycle(ListNode head){
125126
if (head == nil){
126127
return false;
@@ -152,6 +153,23 @@ bool hasCycle(ListNode head){
152153
}
153154
return ret;
154155
}
156+
157+
ListNode l1 = ListNode(1, nil);
158+
bool b1 =hasCycle(l1);
159+
println(b1);
160+
assertEqual(b1, false);
161+
162+
ListNode l4 = ListNode(4, nil);
163+
ListNode l3 = ListNode(3, l4);
164+
ListNode l2 = ListNode(2, l3);
165+
bool b2 = hasCycle(l2);
166+
println(b2);
167+
assertEqual(b2, false);
168+
169+
l4.next = l2;
170+
bool b3 = hasCycle(l2);
171+
println(b3);
172+
assertEqual(b3, true);
155173
```
156174

157175
函数声明语法:`typeTypeOrVoid? IDENTIFIER formalParameters ('[' ']')*`

0 commit comments

Comments
 (0)