Update linked list find loop to return a node (#106)

This commit is contained in:
Donne Martin 2016-10-21 20:27:58 -04:00 committed by GitHub
parent c961a279fc
commit bd89e83b65
3 changed files with 10 additions and 5 deletions

View File

@ -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",

View File

@ -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": [
{

View File

@ -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')