docs(docs): add Approach diagrams and Explanation sections to LeetCode problem documentation

This commit is contained in:
Prad Nukala committed 2026-09-21 15:53:21 -04:00
1 parent b8c779903f
commit 23eb71d387
19 files changed
+439

No files matched your search

@@ -27,6 +27,20 @@ sidebar:
- `0 <= Node.val <= 9`
- It is guaranteed that the list represents a number that does not have leading zeros.
## Approach
```mermaid
flowchart TD
S(["addTwoNumbers(l1, l2)"]) --> I["dummy = ListNode(), carry = 0, curr = dummy — dummy.next will be the head"]
I --> W{"l1 or l2 or carry?"}
W -- no --> E(["return dummy.next"])
W -- yes --> A["s = (l1.val if l1 else 0) + (l2.val if l2 else 0) + carry — a missing digit counts as 0"]
A --> D["carry, val = divmod(s, 10)"]
D --> N["curr.next = ListNode(val), curr = curr.next"]
N --> V["l1 = l1.next if l1 else None, l2 = l2.next if l2 else None"]
V --> W
```
## Solution
```py
@@ -55,3 +69,7 @@ class Solution:
return dummy.next
```
## Explanation
<YouTube id="wgFPrzTjm7s" title="Add Two Numbers - Leetcode 2 - Python" />