Skip to main content
The data structure classes from leetcode_py convert between LeetCode’s array format and live objects, and render themselves so you can look at what your code is doing.

Array format, live objects

Cyclic lists are safe: traversal detects cycles instead of hanging, in both directions.

In Jupyter: diagrams

As the last expression of a cell, these objects render as Graphviz SVG diagrams. TreeNode lays out top-to-bottom; ListNode goes left-to-right with rounded boxes. A cyclic list draws the back-edge in red, dashed, and labeled cycle.
TreeNode rendered as a Graphviz tree diagram in Jupyter ListNode rendered as a left-to-right box diagram in Jupyter

In the terminal: ASCII

print() falls back to clean text: an indented tree, an arrow chain for lists (cycles shown as ... (cycle back to 2)), and a formatted adjacency dict for graphs.
TreeNode printed as an ASCII tree in the terminal ListNode printed as an arrow chain in the terminal

Requirements

Diagram rendering needs the system Graphviz binary (see Installation). If it is missing, the objects fall back to the ASCII form, so you get readable output either way.