We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e5bee08 commit 776ae2eCopy full SHA for 776ae2e
README-ZH.md
@@ -121,6 +121,7 @@ assertEqual(xx.getAge(), 110);
121
## 函数
122
123
```js
124
+// 判断链表是否有环
125
bool hasCycle(ListNode head){
126
if (head == nil){
127
return false;
@@ -152,6 +153,23 @@ bool hasCycle(ListNode head){
152
153
}
154
return ret;
155
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);
173
```
174
175
函数声明语法:`typeTypeOrVoid? IDENTIFIER formalParameters ('[' ']')*`
0 commit comments