|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 5, |
| 6 | + "id": "imports", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "from solution import Solution\n", |
| 11 | + "\n", |
| 12 | + "from leetcode_py import ListNode" |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "code", |
| 17 | + "execution_count": 6, |
| 18 | + "id": "setup", |
| 19 | + "metadata": {}, |
| 20 | + "outputs": [], |
| 21 | + "source": [ |
| 22 | + "# Example test case\n", |
| 23 | + "head_list = [1, 2, 3, 4, 5]\n", |
| 24 | + "expected_list = [3, 4, 5]" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "code", |
| 29 | + "execution_count": 7, |
| 30 | + "id": "execute", |
| 31 | + "metadata": {}, |
| 32 | + "outputs": [ |
| 33 | + { |
| 34 | + "data": { |
| 35 | + "text/html": [ |
| 36 | + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n", |
| 37 | + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n", |
| 38 | + " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n", |
| 39 | + "<!-- Generated by graphviz version 13.1.2 (20250808.2320)\n", |
| 40 | + " -->\n", |
| 41 | + "<!-- Pages: 1 -->\n", |
| 42 | + "<svg width=\"242pt\" height=\"44pt\"\n", |
| 43 | + " viewBox=\"0.00 0.00 242.00 44.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", |
| 44 | + "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 40)\">\n", |
| 45 | + "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-40 238,-40 238,4 -4,4\"/>\n", |
| 46 | + "<!-- node_0 -->\n", |
| 47 | + "<g id=\"node1\" class=\"node\">\n", |
| 48 | + "<title>node_0</title>\n", |
| 49 | + "<path fill=\"lightblue\" stroke=\"black\" d=\"M42,-36C42,-36 12,-36 12,-36 6,-36 0,-30 0,-24 0,-24 0,-12 0,-12 0,-6 6,0 12,0 12,0 42,0 42,0 48,0 54,-6 54,-12 54,-12 54,-24 54,-24 54,-30 48,-36 42,-36\"/>\n", |
| 50 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"27\" y=\"-12.95\" font-family=\"Times,serif\" font-size=\"14.00\">3</text>\n", |
| 51 | + "</g>\n", |
| 52 | + "<!-- node_1 -->\n", |
| 53 | + "<g id=\"node2\" class=\"node\">\n", |
| 54 | + "<title>node_1</title>\n", |
| 55 | + "<path fill=\"lightblue\" stroke=\"black\" d=\"M132,-36C132,-36 102,-36 102,-36 96,-36 90,-30 90,-24 90,-24 90,-12 90,-12 90,-6 96,0 102,0 102,0 132,0 132,0 138,0 144,-6 144,-12 144,-12 144,-24 144,-24 144,-30 138,-36 132,-36\"/>\n", |
| 56 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"117\" y=\"-12.95\" font-family=\"Times,serif\" font-size=\"14.00\">4</text>\n", |
| 57 | + "</g>\n", |
| 58 | + "<!-- node_0->node_1 -->\n", |
| 59 | + "<g id=\"edge1\" class=\"edge\">\n", |
| 60 | + "<title>node_0->node_1</title>\n", |
| 61 | + "<path fill=\"none\" stroke=\"black\" d=\"M54.4,-18C61.89,-18 70.18,-18 78.2,-18\"/>\n", |
| 62 | + "<polygon fill=\"black\" stroke=\"black\" points=\"78.1,-21.5 88.1,-18 78.1,-14.5 78.1,-21.5\"/>\n", |
| 63 | + "</g>\n", |
| 64 | + "<!-- node_2 -->\n", |
| 65 | + "<g id=\"node3\" class=\"node\">\n", |
| 66 | + "<title>node_2</title>\n", |
| 67 | + "<path fill=\"lightblue\" stroke=\"black\" d=\"M222,-36C222,-36 192,-36 192,-36 186,-36 180,-30 180,-24 180,-24 180,-12 180,-12 180,-6 186,0 192,0 192,0 222,0 222,0 228,0 234,-6 234,-12 234,-12 234,-24 234,-24 234,-30 228,-36 222,-36\"/>\n", |
| 68 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"207\" y=\"-12.95\" font-family=\"Times,serif\" font-size=\"14.00\">5</text>\n", |
| 69 | + "</g>\n", |
| 70 | + "<!-- node_1->node_2 -->\n", |
| 71 | + "<g id=\"edge2\" class=\"edge\">\n", |
| 72 | + "<title>node_1->node_2</title>\n", |
| 73 | + "<path fill=\"none\" stroke=\"black\" d=\"M144.4,-18C151.89,-18 160.18,-18 168.2,-18\"/>\n", |
| 74 | + "<polygon fill=\"black\" stroke=\"black\" points=\"168.1,-21.5 178.1,-18 168.1,-14.5 168.1,-21.5\"/>\n", |
| 75 | + "</g>\n", |
| 76 | + "</g>\n", |
| 77 | + "</svg>\n" |
| 78 | + ], |
| 79 | + "text/plain": [ |
| 80 | + "ListNode([3, 4, 5])" |
| 81 | + ] |
| 82 | + }, |
| 83 | + "execution_count": 7, |
| 84 | + "metadata": {}, |
| 85 | + "output_type": "execute_result" |
| 86 | + } |
| 87 | + ], |
| 88 | + "source": [ |
| 89 | + "head = ListNode.from_list(head_list)\n", |
| 90 | + "result = Solution().middle_node(head)\n", |
| 91 | + "result" |
| 92 | + ] |
| 93 | + }, |
| 94 | + { |
| 95 | + "cell_type": "code", |
| 96 | + "execution_count": 8, |
| 97 | + "id": "test", |
| 98 | + "metadata": {}, |
| 99 | + "outputs": [], |
| 100 | + "source": [ |
| 101 | + "expected = ListNode.from_list(expected_list)\n", |
| 102 | + "assert result == expected" |
| 103 | + ] |
| 104 | + } |
| 105 | + ], |
| 106 | + "metadata": { |
| 107 | + "kernelspec": { |
| 108 | + "display_name": "leetcode-py-py3.13", |
| 109 | + "language": "python", |
| 110 | + "name": "python3" |
| 111 | + }, |
| 112 | + "language_info": { |
| 113 | + "codemirror_mode": { |
| 114 | + "name": "ipython", |
| 115 | + "version": 3 |
| 116 | + }, |
| 117 | + "file_extension": ".py", |
| 118 | + "mimetype": "text/x-python", |
| 119 | + "name": "python", |
| 120 | + "nbconvert_exporter": "python3", |
| 121 | + "pygments_lexer": "ipython3", |
| 122 | + "version": "3.13.7" |
| 123 | + } |
| 124 | + }, |
| 125 | + "nbformat": 4, |
| 126 | + "nbformat_minor": 5 |
| 127 | +} |
0 commit comments