From bd89e83b65e341a68c477b8cfed8355e2751ee6e Mon Sep 17 00:00:00 2001 From: Donne Martin Date: Fri, 21 Oct 2016 20:27:58 -0400 Subject: [PATCH] Update linked list find loop to return a node (#106) --- .../find_loop_start/find_loop_start_challenge.ipynb | 4 +++- .../find_loop_start/find_loop_start_solution.ipynb | 9 ++++++--- linked_lists/find_loop_start/test_find_loop_start.py | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/linked_lists/find_loop_start/find_loop_start_challenge.ipynb b/linked_lists/find_loop_start/find_loop_start_challenge.ipynb index ebc018b..89ffe39 100644 --- a/linked_lists/find_loop_start/find_loop_start_challenge.ipynb +++ b/linked_lists/find_loop_start/find_loop_start_challenge.ipynb @@ -38,6 +38,8 @@ " * Yes\n", "* Can we assume we are always passed a circular linked list?\n", " * No\n", + "* When we find a loop, do we return the node or the node's data?\n", + " * The node\n", "* Can we assume we already have a linked list class that can be used for this problem?\n", " * Yes" ] @@ -160,7 +162,7 @@ " node0 = Node(0, node1)\n", " node10.next = node3\n", " linked_list = MyLinkedList(node0)\n", - " assert_equal(linked_list.find_loop_start(), 3)\n", + " assert_equal(linked_list.find_loop_start(), node3)\n", "\n", " print('Success: test_find_loop_start')\n", "\n", diff --git a/linked_lists/find_loop_start/find_loop_start_solution.ipynb b/linked_lists/find_loop_start/find_loop_start_solution.ipynb index bd897cf..aac9208 100644 --- a/linked_lists/find_loop_start/find_loop_start_solution.ipynb +++ b/linked_lists/find_loop_start/find_loop_start_solution.ipynb @@ -37,6 +37,8 @@ " * Yes\n", "* Can we assume we are always passed a circular linked list?\n", " * No\n", + "* When we find a loop, do we return the node or the node's data?\n", + " * The node\n", "* Can we assume we already have a linked list class that can be used for this problem?\n", " * Yes" ] @@ -119,7 +121,7 @@ " fast = fast.next\n", " if fast is None:\n", " return None\n", - " return slow.data" + " return slow" ] }, { @@ -183,7 +185,7 @@ " node0 = Node(0, node1)\n", " node10.next = node3\n", " linked_list = MyLinkedList(node0)\n", - " assert_equal(linked_list.find_loop_start(), 3)\n", + " assert_equal(linked_list.find_loop_start(), node3)\n", "\n", " print('Success: test_find_loop_start')\n", "\n", @@ -201,7 +203,8 @@ "cell_type": "code", "execution_count": 4, "metadata": { - "collapsed": false + "collapsed": false, + "scrolled": true }, "outputs": [ { diff --git a/linked_lists/find_loop_start/test_find_loop_start.py b/linked_lists/find_loop_start/test_find_loop_start.py index 8ced37d..fc8118c 100644 --- a/linked_lists/find_loop_start/test_find_loop_start.py +++ b/linked_lists/find_loop_start/test_find_loop_start.py @@ -35,7 +35,7 @@ class TestFindLoopStart(object): node0 = Node(0, node1) node10.next = node3 linked_list = MyLinkedList(node0) - assert_equal(linked_list.find_loop_start(), 3) + assert_equal(linked_list.find_loop_start(), node3) print('Success: test_find_loop_start')