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