From 8b16b392f25d350e6f0d48068abcf443fa272436 Mon Sep 17 00:00:00 2001 From: Ali Nawaz <110383490+AliPythonDev@users.noreply.github.com> Date: Tue, 16 Apr 2024 12:08:13 +0500 Subject: [PATCH 1/2] Update README.md --- .../0404.Sum of Left Leaves/README.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/solution/0400-0499/0404.Sum of Left Leaves/README.md b/solution/0400-0499/0404.Sum of Left Leaves/README.md index 9565bc2d34c66..ca946d181e123 100644 --- a/solution/0400-0499/0404.Sum of Left Leaves/README.md +++ b/solution/0400-0499/0404.Sum of Left Leaves/README.md @@ -219,6 +219,27 @@ int sumOfLeftLeaves(struct TreeNode* root) { } ``` +```cpp +class Solution { + public: + int sumOfLeftLeaves(TreeNode* root) { + if (root == nullptr) + return 0; + + int ans = 0; + + if (root->left) { + if (root->left->left == nullptr && root->left->right == nullptr) + ans += root->left->val; + else + ans += sumOfLeftLeaves(root->left); + } + ans += sumOfLeftLeaves(root->right); + + return ans; + } +}; +``` From 9d1562f341454de6ca87e31d71bbce2b977d94a5 Mon Sep 17 00:00:00 2001 From: AliPythonDev Date: Tue, 16 Apr 2024 07:19:23 +0000 Subject: [PATCH 2/2] style: format code and docs with prettier --- solution/0400-0499/0404.Sum of Left Leaves/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/solution/0400-0499/0404.Sum of Left Leaves/README.md b/solution/0400-0499/0404.Sum of Left Leaves/README.md index ca946d181e123..a9b4f2c779bf6 100644 --- a/solution/0400-0499/0404.Sum of Left Leaves/README.md +++ b/solution/0400-0499/0404.Sum of Left Leaves/README.md @@ -240,6 +240,7 @@ class Solution { } }; ``` +