|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "imports", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "from solution import Solution\n", |
| 11 | + "\n", |
| 12 | + "from leetcode_py import TreeNode" |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "code", |
| 17 | + "execution_count": 2, |
| 18 | + "id": "setup", |
| 19 | + "metadata": {}, |
| 20 | + "outputs": [], |
| 21 | + "source": [ |
| 22 | + "# Example test case\n", |
| 23 | + "root_list = [3, 9, 20, None, None, 15, 7]\n", |
| 24 | + "expected = 3" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "code", |
| 29 | + "execution_count": 3, |
| 30 | + "id": "execute", |
| 31 | + "metadata": {}, |
| 32 | + "outputs": [ |
| 33 | + { |
| 34 | + "data": { |
| 35 | + "text/plain": [ |
| 36 | + "3" |
| 37 | + ] |
| 38 | + }, |
| 39 | + "execution_count": 3, |
| 40 | + "metadata": {}, |
| 41 | + "output_type": "execute_result" |
| 42 | + } |
| 43 | + ], |
| 44 | + "source": [ |
| 45 | + "root = TreeNode.from_list(root_list)\n", |
| 46 | + "result = Solution().max_depth(root)\n", |
| 47 | + "result" |
| 48 | + ] |
| 49 | + }, |
| 50 | + { |
| 51 | + "cell_type": "code", |
| 52 | + "execution_count": 5, |
| 53 | + "id": "3d476584", |
| 54 | + "metadata": {}, |
| 55 | + "outputs": [ |
| 56 | + { |
| 57 | + "data": { |
| 58 | + "text/html": [ |
| 59 | + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n", |
| 60 | + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n", |
| 61 | + " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n", |
| 62 | + "<!-- Generated by graphviz version 13.1.2 (20250808.2320)\n", |
| 63 | + " -->\n", |
| 64 | + "<!-- Pages: 1 -->\n", |
| 65 | + "<svg width=\"170pt\" height=\"188pt\"\n", |
| 66 | + " viewBox=\"0.00 0.00 170.00 188.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", |
| 67 | + "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 184)\">\n", |
| 68 | + "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-184 166,-184 166,4 -4,4\"/>\n", |
| 69 | + "<!-- 0 -->\n", |
| 70 | + "<g id=\"node1\" class=\"node\">\n", |
| 71 | + "<title>0</title>\n", |
| 72 | + "<ellipse fill=\"none\" stroke=\"black\" cx=\"63\" cy=\"-162\" rx=\"27\" ry=\"18\"/>\n", |
| 73 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"63\" y=\"-156.95\" font-family=\"Times,serif\" font-size=\"14.00\">3</text>\n", |
| 74 | + "</g>\n", |
| 75 | + "<!-- 1 -->\n", |
| 76 | + "<g id=\"node2\" class=\"node\">\n", |
| 77 | + "<title>1</title>\n", |
| 78 | + "<ellipse fill=\"none\" stroke=\"black\" cx=\"27\" cy=\"-90\" rx=\"27\" ry=\"18\"/>\n", |
| 79 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"27\" y=\"-84.95\" font-family=\"Times,serif\" font-size=\"14.00\">9</text>\n", |
| 80 | + "</g>\n", |
| 81 | + "<!-- 0->1 -->\n", |
| 82 | + "<g id=\"edge1\" class=\"edge\">\n", |
| 83 | + "<title>0->1</title>\n", |
| 84 | + "<path fill=\"none\" stroke=\"black\" d=\"M54.65,-144.76C50.42,-136.55 45.19,-126.37 40.42,-117.09\"/>\n", |
| 85 | + "<polygon fill=\"black\" stroke=\"black\" points=\"43.68,-115.79 36,-108.49 37.46,-118.99 43.68,-115.79\"/>\n", |
| 86 | + "</g>\n", |
| 87 | + "<!-- 2 -->\n", |
| 88 | + "<g id=\"node3\" class=\"node\">\n", |
| 89 | + "<title>2</title>\n", |
| 90 | + "<ellipse fill=\"none\" stroke=\"black\" cx=\"99\" cy=\"-90\" rx=\"27\" ry=\"18\"/>\n", |
| 91 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"99\" y=\"-84.95\" font-family=\"Times,serif\" font-size=\"14.00\">20</text>\n", |
| 92 | + "</g>\n", |
| 93 | + "<!-- 0->2 -->\n", |
| 94 | + "<g id=\"edge2\" class=\"edge\">\n", |
| 95 | + "<title>0->2</title>\n", |
| 96 | + "<path fill=\"none\" stroke=\"black\" d=\"M71.35,-144.76C75.58,-136.55 80.81,-126.37 85.58,-117.09\"/>\n", |
| 97 | + "<polygon fill=\"black\" stroke=\"black\" points=\"88.54,-118.99 90,-108.49 82.32,-115.79 88.54,-118.99\"/>\n", |
| 98 | + "</g>\n", |
| 99 | + "<!-- 3 -->\n", |
| 100 | + "<g id=\"node4\" class=\"node\">\n", |
| 101 | + "<title>3</title>\n", |
| 102 | + "<ellipse fill=\"none\" stroke=\"black\" cx=\"63\" cy=\"-18\" rx=\"27\" ry=\"18\"/>\n", |
| 103 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"63\" y=\"-12.95\" font-family=\"Times,serif\" font-size=\"14.00\">15</text>\n", |
| 104 | + "</g>\n", |
| 105 | + "<!-- 2->3 -->\n", |
| 106 | + "<g id=\"edge3\" class=\"edge\">\n", |
| 107 | + "<title>2->3</title>\n", |
| 108 | + "<path fill=\"none\" stroke=\"black\" d=\"M90.65,-72.76C86.42,-64.55 81.19,-54.37 76.42,-45.09\"/>\n", |
| 109 | + "<polygon fill=\"black\" stroke=\"black\" points=\"79.68,-43.79 72,-36.49 73.46,-46.99 79.68,-43.79\"/>\n", |
| 110 | + "</g>\n", |
| 111 | + "<!-- 4 -->\n", |
| 112 | + "<g id=\"node5\" class=\"node\">\n", |
| 113 | + "<title>4</title>\n", |
| 114 | + "<ellipse fill=\"none\" stroke=\"black\" cx=\"135\" cy=\"-18\" rx=\"27\" ry=\"18\"/>\n", |
| 115 | + "<text xml:space=\"preserve\" text-anchor=\"middle\" x=\"135\" y=\"-12.95\" font-family=\"Times,serif\" font-size=\"14.00\">7</text>\n", |
| 116 | + "</g>\n", |
| 117 | + "<!-- 2->4 -->\n", |
| 118 | + "<g id=\"edge4\" class=\"edge\">\n", |
| 119 | + "<title>2->4</title>\n", |
| 120 | + "<path fill=\"none\" stroke=\"black\" d=\"M107.35,-72.76C111.58,-64.55 116.81,-54.37 121.58,-45.09\"/>\n", |
| 121 | + "<polygon fill=\"black\" stroke=\"black\" points=\"124.54,-46.99 126,-36.49 118.32,-43.79 124.54,-46.99\"/>\n", |
| 122 | + "</g>\n", |
| 123 | + "</g>\n", |
| 124 | + "</svg>\n" |
| 125 | + ], |
| 126 | + "text/plain": [ |
| 127 | + "TreeNode([3, 9, 20, None, None, 15, 7])" |
| 128 | + ] |
| 129 | + }, |
| 130 | + "execution_count": 5, |
| 131 | + "metadata": {}, |
| 132 | + "output_type": "execute_result" |
| 133 | + } |
| 134 | + ], |
| 135 | + "source": [ |
| 136 | + "root" |
| 137 | + ] |
| 138 | + }, |
| 139 | + { |
| 140 | + "cell_type": "code", |
| 141 | + "execution_count": 4, |
| 142 | + "id": "test", |
| 143 | + "metadata": {}, |
| 144 | + "outputs": [], |
| 145 | + "source": [ |
| 146 | + "assert result == expected" |
| 147 | + ] |
| 148 | + } |
| 149 | + ], |
| 150 | + "metadata": { |
| 151 | + "kernelspec": { |
| 152 | + "display_name": "leetcode-py-py3.13", |
| 153 | + "language": "python", |
| 154 | + "name": "python3" |
| 155 | + }, |
| 156 | + "language_info": { |
| 157 | + "codemirror_mode": { |
| 158 | + "name": "ipython", |
| 159 | + "version": 3 |
| 160 | + }, |
| 161 | + "file_extension": ".py", |
| 162 | + "mimetype": "text/x-python", |
| 163 | + "name": "python", |
| 164 | + "nbconvert_exporter": "python", |
| 165 | + "pygments_lexer": "ipython3", |
| 166 | + "version": "3.13.7" |
| 167 | + } |
| 168 | + }, |
| 169 | + "nbformat": 4, |
| 170 | + "nbformat_minor": 5 |
| 171 | +} |
0 commit comments