[ 命名建議 ] LeetCode 141. Linked List Cycle #121
Answered
by
twy30
LPenny-github
asked this question in
Q&A
-
|
LeetCode: 線上教材: 再麻煩 @twy30 給予命名建議 orz 感激不盡 public class Solution
{
public bool HasCycle(ListNode head)
{
ListNode headNode = head;
ListNode fastNodeDetector = head;
ListNode slowNodeDetector = head;
while (fastNodeDetector?.next != null)
{
fastNodeDetector = fastNodeDetector.next.next;
slowNodeDetector = slowNodeDetector.next;
if (fastNodeDetector == slowNodeDetector)
{
return true;
}
}
return false;
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
twy30
Feb 5, 2021
Replies: 1 comment 1 reply
-
|
你好 😊 我覺得這題用 我會把
這兩種寫法在語意上有些差異:
可以參考看看 😊 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
LPenny-github
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@LPenny-github
你好 😊
我覺得這題用
fast,slow很棒,直覺好懂 👍我會把
NodeDetector換成Iterator( https://zh.wikipedia.org/zh-tw/%E8%BF%AD%E4%BB%A3%E5%99%A8 ), 變成fastIteratorslowIterator這兩種寫法在語意上有些差異:
fastNodeDetectorfastIterator可以參考看看 😊