question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
check-if-the-number-is-fascinating
Python3 Solution
python3-solution-by-motaharozzaman1996-hgk1
\n\nclass Solution:\n def isFascinating(self, n: int) -> bool:\n return sorted(str(n)+str(2*n)+str(3*n))==list(map(str,range(1,10)))\n
Motaharozzaman1996
NORMAL
2023-06-10T17:04:44.322669+00:00
2023-06-10T17:04:44.322714+00:00
150
false
\n```\nclass Solution:\n def isFascinating(self, n: int) -> bool:\n return sorted(str(n)+str(2*n)+str(3*n))==list(map(str,range(1,10)))\n```
1
0
['Python', 'Python3']
0
check-if-the-number-is-fascinating
Very Simple Solution!!!
very-simple-solution-by-yashpadiyar4-9tpp
\n\n# Code\n\nclass Solution {\npublic:\n bool isFascinating(int n) {\n string s=to_string(n);\n string s1=to_string(2*n);\n string s2=t
yashpadiyar4
NORMAL
2023-06-10T16:04:29.744832+00:00
2023-06-10T16:04:29.744869+00:00
389
false
\n\n# Code\n```\nclass Solution {\npublic:\n bool isFascinating(int n) {\n string s=to_string(n);\n string s1=to_string(2*n);\n string s2=to_string(3*n);\n string s3=s+s1+s2;\n vector<int>vis(10000,0);\n for(int i=0;i<s3.size();i++){\n vis[s3[i]-\'0\']++;\n ...
1
0
['C++']
1
check-if-the-number-is-fascinating
Check if The Number is Fascinating
check-if-the-number-is-fascinating-by-sa-c3bv
IntuitionThe key observation is that a fascinating number, when concatenated with its multiples 2n and 3n, must contain each of the digits 1 through 9 exactly o
sania_sial
NORMAL
2025-04-11T06:24:27.733982+00:00
2025-04-11T06:24:27.733982+00:00
1
false
![i1.png](https://assets.leetcode.com/users/images/ee0270db-f6f6-4cf6-8a5b-8c39232ec7d7_1744352654.3690531.png) # Intuition The key observation is that a fascinating number, when concatenated with its multiples 2n and 3n, must contain each of the digits 1 through 9 exactly once. By concatenating these values and then...
0
0
['Math', 'Python3']
0
check-if-the-number-is-fascinating
Python Easy Solution
python-easy-solution-by-vini__7-5emd
IntuitionApproachComplexity Time complexity: Space complexity: Code
Vini__7
NORMAL
2025-04-07T16:32:28.393685+00:00
2025-04-07T16:32:28.393685+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python3']
0
check-if-the-number-is-fascinating
Luke - is fascinating solution
luke-is-fascinating-solution-by-thunderl-o8nl
IntuitionApproachI used 3 int variables. One of them is the int n value, the other is n2, while the other is n3. I converted all these 3 int variables to string
thunderlukey
NORMAL
2025-04-06T18:33:58.145483+00:00
2025-04-06T18:33:58.145483+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> I used 3 int variables. One of them is the int n value, the other is n*2, while the other is n*3. I converted all these 3 int variables to strings. I combined these three s...
0
0
['Java']
0
check-if-the-number-is-fascinating
alternative solution using numbers and sets
alternative-solution-using-numbers-and-s-8u0k
IntuitionApproachComplexity Time complexity: Space complexity: Code
dpasala
NORMAL
2025-04-04T02:56:44.484563+00:00
2025-04-04T02:56:44.484563+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Number Theory', 'Ordered Set', 'Java']
0
check-if-the-number-is-fascinating
beats 80% runtime (stringbuilder solution)
beats-80-runtime-stringbuilder-solution-31393
IntuitionApproachComplexity Time complexity: Space complexity: Code
dpasala
NORMAL
2025-04-04T02:53:13.379330+00:00
2025-04-04T02:53:13.379330+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0
check-if-the-number-is-fascinating
Check if The Number is Fascinating
check-if-the-number-is-fascinating-by-su-r7uy
IntuitionApproachComplexity Time complexity: Space complexity: Code
suyunovshohjahon08
NORMAL
2025-04-03T01:41:02.686452+00:00
2025-04-03T01:41:02.686452+00:00
1
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['TypeScript']
0
check-if-the-number-is-fascinating
Concatenation solution
concatenation-solution-by-ezpectus-pm9i
Approach:Concatenate the numbers:We use string interpolation ($"{n}{n * 2}{n * 3}") to create the concatenated string. Check the length: The concatenated string
ezpectus
NORMAL
2025-03-31T22:51:49.723321+00:00
2025-03-31T22:51:49.723321+00:00
2
false
Approach: Concatenate the numbers: We use string interpolation ($"{n}{n * 2}{n * 3}") to create the concatenated string. Check the length: The concatenated string must have a length of 9. Check for '0': The concatenated string must not contain the digit '0'. Check for unique digits: The concatenated string must cont...
0
0
['Hash Table', 'Math', 'C#']
0
check-if-the-number-is-fascinating
C++ math approach, string concatenation w/ a set, and the optimal solution
c-math-approach-string-concatenation-w-a-0f5m
Math Approach (no strings)Note: Since n is an integer from [100, 999] we don't have to check for n == 0 thus a log10 function is good since n > 0. For this to w
iwat1874
NORMAL
2025-03-31T08:20:45.133945+00:00
2025-03-31T08:20:45.133945+00:00
3
false
# Math Approach (no strings) <!-- Describe your approach to solving the problem. --> **Note:** Since n is an integer from [100, 999] we don't have to check for n == 0 thus a log10 function is good since n > 0. 1) For this to work, we need to either check if the 3n is a 4 digit number and if it is, we return false. 2)...
0
0
['C++']
0
check-if-the-number-is-fascinating
Simple code beats 100% with comments
simple-code-beats-100-with-comments-by-r-tzsw
IntuitionNo idea at firstApproachWe just check if there are zeros, duplicates, and the length is 9. If all True then return True. Else return FalseComplexity Ti
RandomUser3456
NORMAL
2025-03-30T22:20:09.913342+00:00
2025-03-30T22:20:09.913342+00:00
5
false
# Intuition No idea at first # Approach We just check if there are zeros, duplicates, and the length is 9. If all True then return True. Else return False # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> ...
0
0
['Python3']
0
check-if-the-number-is-fascinating
Fast no comment (no time to explain version)
fast-no-comment-no-time-to-explain-versi-529y
IntuitionApproachComplexity Time complexity: Space complexity: Code
RandomUser3456
NORMAL
2025-03-30T22:16:39.361633+00:00
2025-03-30T22:16:39.361633+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python3']
0
check-if-the-number-is-fascinating
2-line fascinating solution
2-line-fascinating-solution-by-mleo8-nith
Code
mleo8
NORMAL
2025-03-27T17:35:52.213300+00:00
2025-03-27T17:35:52.213300+00:00
2
false
# Code ```python3 [] class Solution: def isFascinating(self, n: int) -> bool: s = str(n) + str(n * 2) + str(n * 3) return len(s) == 9 and set(s) == set("123456789") ```
0
0
['Python3']
0
check-if-the-number-is-fascinating
🔥✅✅ Dart Solution 📌📌 || with Explanation 👌👌
dart-solution-with-explanation-by-nosar-76xe
Solution Numbers that produce concatenated results with incorrect lengths (either too short or too long) Numbers that contain zeros in any of n, 2n, or 3n Numbe
NosaR
NORMAL
2025-03-27T01:45:41.860828+00:00
2025-03-27T01:45:41.860828+00:00
3
false
# Solution - Numbers that produce concatenated results with incorrect lengths (either too short or too long) - Numbers that contain zeros in any of n, 2n, or 3n - Numbers that have duplicate digits in the concatenated result - Numbers that don't cover all digits from 1-9 ### Time Complexity: **Overall Time Complexit...
0
0
['Dart']
0
check-if-the-number-is-fascinating
another variant
another-variant-by-mattwix-fnjk
IntuitionApproachComplexity Time complexity: Space complexity: Code
MatTwix
NORMAL
2025-03-22T20:50:31.624977+00:00
2025-03-22T20:50:31.624977+00:00
1
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Go']
0
check-if-the-number-is-fascinating
Easy to understand solution in Java.
easy-to-understand-solution-in-java-by-k-azql
Complexity Time complexity: O(logn) Space complexity: O(logn) Code
Khamdam
NORMAL
2025-03-21T07:45:30.950399+00:00
2025-03-21T07:45:30.950399+00:00
4
false
# Complexity - Time complexity: O(logn) - Space complexity: O(logn) # Code ```java [] class Solution { public boolean isFascinating(int n) { StringBuilder sb = new StringBuilder(); String concat = sb.append(n).append(2 * n).append(3 * n).toString(); int m = concat.length(); int[] f...
0
0
['Java']
0
check-if-the-number-is-fascinating
Easy Approach
easy-approach-by-kunal_1310-lo3o
IntuitionApproachComplexity Time complexity: Space complexity: Code
kunal_1310
NORMAL
2025-03-20T08:33:37.778041+00:00
2025-03-20T08:33:37.778041+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C++']
0
check-if-the-number-is-fascinating
using python
using-python-by-bhabanisbiswal-imjc
IntuitionApproachComplexity Time complexity: Space complexity: Code
bhabanisbiswal
NORMAL
2025-03-15T14:35:04.942823+00:00
2025-03-15T14:35:04.942823+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python']
0
check-if-the-number-is-fascinating
Runtime: 0 ms, Beats 100%
runtime-0-ms-beats-100-by-singhalearn03-s3s3
IntuitionThe problem requires checking whether a given three-digit number n satisfies the fascinating number property. The key observation here is that a fascin
singhalearn03
NORMAL
2025-03-12T07:35:08.612079+00:00
2025-03-12T07:35:08.612079+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> The problem requires checking whether a given three-digit number n satisfies the fascinating number property. The key observation here is that a fascinating number, when concatenated with its twice and thrice multiples, should form a 9-digi...
0
0
['Python']
0
check-if-the-number-is-fascinating
Super easy to understand solution -->> Beats 100.00%
super-easy-to-understand-solution-beats-64buz
IntuitionApproachComplexity Time complexity: O(n) Space complexity: O(1) Code
DevelopersUsername
NORMAL
2025-03-07T18:05:10.300127+00:00
2025-03-07T18:05:10.300127+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(n) - Space complexity: O(1) # Code ```java [] class Solution { public boolean isFascinating(int n) { int[] count = new int...
0
0
['Java']
0
check-if-the-number-is-fascinating
python beats 100% speed
python-beats-100-speed-by-adamliewehr-cciz
IntuitionApproachComplexity Time complexity: Space complexity: Code
adamliewehr
NORMAL
2025-02-25T00:16:20.186296+00:00
2025-02-25T00:16:20.186296+00:00
6
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python3']
0
check-if-the-number-is-fascinating
Easy and Simple C++ using Strings.
easy-and-simple-c-using-strings-by-mishr-7duj
IntuitionThis is a easy problem you just have to change the type of data structure. That's it for thisApproach First Calculate the Multiplication with 2 and 3 a
mishrasuyash013
NORMAL
2025-02-22T21:20:54.303385+00:00
2025-02-22T21:20:54.303385+00:00
4
false
# Intuition This is a easy problem you just have to change the type of data structure. That's it for this # Approach - First Calculate the Multiplication with 2 and 3 and store them. - Then Convert these into String Using the to_String() function. - Then declare 2 string one is empty and other with number from 1 to 9....
0
0
['C++']
0
check-if-the-number-is-fascinating
100% beats solution
100-beats-solution-by-yashchandola12-opp6
IntuitionApproachComplexity Time complexity: Space complexity: Code
yashchandola12
NORMAL
2025-02-22T13:18:29.026448+00:00
2025-02-22T13:18:29.026448+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python']
0
check-if-the-number-is-fascinating
Beats 100% time and space || Simple C++ Solution
beats-100-time-and-space-simple-c-soluti-rqc4
IntuitionApproachComplexity Time complexity: O(N) Space complexity: O(1) Code
Devanshv123
NORMAL
2025-02-20T14:37:12.484292+00:00
2025-02-20T14:37:12.484292+00:00
4
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach ![Screenshot 2025-02-20 200548.png](https://assets.leetcode.com/users/images/65775cec-1879-4b1e-b79d-c9d43d7498d3_1740062199.9284165.png) <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O...
0
0
['Hash Table', 'Math', 'C++']
0
check-if-the-number-is-fascinating
BEATS 100% EASY PYTHON CODE
beats-100-easy-python-code-by-vishnuande-luaa
Code
vishnuande2006
NORMAL
2025-02-08T14:51:21.975596+00:00
2025-02-08T14:51:21.975596+00:00
3
false
# Code ```python3 [] class Solution: def isFascinating(self, n: int) -> bool: a = n*2 b = n*3 c =str(n)+str(a)+str(b) d = "123456789" if len(c)!=9: return False for i in d: if i not in c: return False return True ```
0
0
['Python3']
0
check-if-the-number-is-fascinating
Super Easy Solution | Beginner Friendly | Beats 100%
super-easy-solution-beginner-friendly-be-olzl
Code
udaisaikiran
NORMAL
2025-02-07T18:50:52.253993+00:00
2025-02-07T18:50:52.253993+00:00
2
false
# Code ```python3 [] class Solution: def isFascinating(self, n: int) -> bool: res="" d="123456789" res+=str(n)+str(2*n)+str(3*n) if len(res)!=9: return False for i in d: if i not in res: return False return True ```
0
0
['Python3']
0
check-if-the-number-is-fascinating
Simple Java Solution
simple-java-solution-by-gopika_kathir-h3t3
IntuitionApproachComplexity Time complexity: Space complexity: Code
Gopika_kathir
NORMAL
2025-02-06T10:33:13.435417+00:00
2025-02-06T10:33:13.435417+00:00
6
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0
check-if-the-number-is-fascinating
easy
easy-by-hemu1817-9ybj
IntuitionApproachComplexity Time complexity: Space complexity: Code
hemu1817
NORMAL
2025-02-05T16:47:19.616237+00:00
2025-02-05T16:47:19.616237+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python']
0
check-if-the-number-is-fascinating
TIME COMPLEXITY - O(1)
time-complexity-o1-by-its_gokhul-84xj
IntuitionApproachComplexity Time complexity: Space complexity: Code
its_gokhul
NORMAL
2025-02-01T14:37:34.528155+00:00
2025-02-01T14:37:34.528155+00:00
3
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0
check-if-the-number-is-fascinating
easy java solution using for loop
easy-java-solution-using-for-loop-by-cha-fad6
IntuitionApproachComplexity Time complexity: Space complexity: Code
chandan_kr1
NORMAL
2025-01-31T17:34:19.573551+00:00
2025-01-31T17:34:19.573551+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0
check-if-the-number-is-fascinating
[C++] Simple Solution
c-simple-solution-by-samuel3shin-zrqz
Code
Samuel3Shin
NORMAL
2025-01-28T16:05:00.010045+00:00
2025-01-28T16:05:00.010045+00:00
5
false
# Code ```cpp [] class Solution { public: vector<int> v; void helper(int n) { while(n > 0) { v[n%10]++; n/=10; } } bool isFascinating(int n) { v.resize(10, 0); int n2 = n*2; int n3 = n*3; helper(n); helper(n2); help...
0
0
['C++']
0
check-if-the-number-is-fascinating
Python 3 - Beats 100 - Super Simple
python-3-beats-100-super-simple-by-zacha-t5xn
IntuitionApproachComplexity Time complexity: Space complexity: Code
zacharylupstein
NORMAL
2025-01-28T15:40:07.032320+00:00
2025-01-28T15:40:07.032320+00:00
2
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python3']
0
check-if-the-number-is-fascinating
C++ 0ms 100% without string, sort...
c-0ms-100-without-string-sort-by-fredo30-0e4d
Code
fredo30400
NORMAL
2025-01-25T17:54:22.728234+00:00
2025-01-25T17:54:22.728234+00:00
3
false
# Code ```cpp [] class Solution { public: bool isFascinating(int n) { if(n>329)return false; // if over two 3(before 333) or more than 9 numbers int a = 2*n; int b = 3*n; n = n*1000000+a*1000+b; //insert all 9 numbers in n int numbers[10]={0}; //for counting each numbers 0 ...
0
0
['C++']
0
path-sum
[Accepted]My recursive solution in Java
acceptedmy-recursive-solution-in-java-by-xvzx
The basic idea is to subtract the value of current node from sum until it reaches a leaf node and the subtraction equals 0, then we know that we got a hit. Othe
boy27910230
NORMAL
2014-09-05T14:40:54+00:00
2018-10-25T18:37:28.662873+00:00
109,182
false
The basic idea is to subtract the value of current node from sum until it reaches a leaf node and the subtraction equals 0, then we know that we got a hit. Otherwise the subtraction at the end could not be 0.\n\n public class Solution {\n public boolean hasPathSum(TreeNode root, int sum) {\n if(roo...
697
7
[]
75
path-sum
Short Python recursive solution - O(n)
short-python-recursive-solution-on-by-go-5d28
# Definition for a binary tree node\n # class TreeNode:\n # def __init__(self, x):\n # self.val = x\n # self.left = None\n #
google
NORMAL
2015-03-21T06:33:10+00:00
2018-10-23T16:18:36.347201+00:00
56,005
false
# Definition for a binary tree node\n # class TreeNode:\n # def __init__(self, x):\n # self.val = x\n # self.left = None\n # self.right = None\n \n class Solution:\n # @param root, a tree node\n # @param sum, an integer\n # @return a boolean\n ...
442
2
['Python']
65
path-sum
3 lines of c++ solution
3-lines-of-c-solution-by-pankit-sbzi
bool hasPathSum(TreeNode *root, int sum) {\n if (root == NULL) return false;\n if (root->val == sum && root->left == NULL && root->right
pankit
NORMAL
2015-03-06T13:40:43+00:00
2018-10-17T17:44:43.794599+00:00
51,242
false
bool hasPathSum(TreeNode *root, int sum) {\n if (root == NULL) return false;\n if (root->val == sum && root->left == NULL && root->right == NULL) return true;\n return hasPathSum(root->left, sum-root->val) || hasPathSum(root->right, sum-root->val);\n }
419
4
[]
32
path-sum
✅Easy Solution🔥Python3/C/C#/C++/Java🔥Explain Line By Line🔥With🗺️Image🗺️
easy-solutionpython3cccjavaexplain-line-zwis1
Problem\nYou\'re given a binary tree and an integer targetSum. The task is to determine whether there exists a root-to-leaf path in the tree where the sum of th
MrAke
NORMAL
2023-08-29T19:13:26.143600+00:00
2023-08-29T19:13:26.143621+00:00
48,257
false
# Problem\nYou\'re given a binary tree and an integer targetSum. The task is to determine whether there exists a root-to-leaf path in the tree where the sum of the values of the nodes along the path equals the targetSum.\n\nIn other words, you need to check if there\'s a sequence of nodes starting from the root and fol...
400
1
['C', 'Python', 'C++', 'Java', 'Python3', 'C#']
9
path-sum
Python solutions (DFS recursively, DFS+stack, BFS+queue)
python-solutions-dfs-recursively-dfsstac-kb5v
DFS Recursively \n def hasPathSum1(self, root, sum):\n res = []\n self.dfs(root, sum, res)\n return any(res)\n \n def dfs(self
oldcodingfarmer
NORMAL
2015-07-11T09:10:26+00:00
2020-09-06T15:38:43.498369+00:00
32,389
false
# DFS Recursively \n def hasPathSum1(self, root, sum):\n res = []\n self.dfs(root, sum, res)\n return any(res)\n \n def dfs(self, root, target, res):\n if root:\n if not root.left and not root.right and root.val == target:\n res.append(True)\n ...
238
0
['Stack', 'Depth-First Search', 'Breadth-First Search', 'Queue', 'Python']
21
path-sum
[C++] Recursive solution {4 lines code}
c-recursive-solution-4-lines-code-by-shu-3m9x
Pls upvote if you find this helpful :)\n\nThree things to remember while solving any recursion based questions are:\n1)Terminating condition/Base Case\n2)Body
shubhambhatt__
NORMAL
2020-06-04T18:06:49.709737+00:00
2020-06-04T18:07:37.290284+00:00
16,732
false
***Pls upvote if you find this helpful :)***\n\nThree things to remember while solving any recursion based questions are:\n1)Terminating condition/Base Case\n2)Body (Code to be performed each time)\n3)Propagation(Calling itself,propagating further)\n```\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, i...
214
2
['Recursion', 'C', 'C++']
9
path-sum
Easiest Beginner Friendly Sol || Recursion || O(n) time and O(h) space
easiest-beginner-friendly-sol-recursion-f4m0q
Intuition\n- We are using top down recursion approach to solve this problem.\n- See below solution to understand how we can use top down and bottom up approach
singhabhinash
NORMAL
2023-01-25T05:01:47.621123+00:00
2023-01-25T05:05:51.466771+00:00
27,019
false
# Intuition\n- We are using **top down recursion** approach to solve this problem.\n- See below solution to understand how we can use top down and bottom up approach in recursion.\nhttps://leetcode.com/problems/maximum-depth-of-binary-tree/solutions/3093043/easiest-beginner-friendly-solution-dfs-o-n-time-and-o-h-space/...
151
1
['Binary Tree', 'Python', 'C++', 'Java']
6
path-sum
Java solution, both recursion and iteration
java-solution-both-recursion-and-iterati-4v7i
\n public boolean hasPathSum(TreeNode root, int sum) {\n // iteration method\n if (root == null) {return false;}\n Stack path = new Stac
young_stone
NORMAL
2015-07-19T17:07:29+00:00
2018-10-22T19:41:08.863591+00:00
15,583
false
\n public boolean hasPathSum(TreeNode root, int sum) {\n // iteration method\n if (root == null) {return false;}\n Stack<TreeNode> path = new Stack<>();\n Stack<Integer> sub = new Stack<>();\n path.push(root);\n sub.push(root.val);\n while (!path.isEmpty()) {\n ...
88
1
['Java']
12
path-sum
[Accepted] By using postorder traversal
accepted-by-using-postorder-traversal-by-c826
In the postorder traversal, the node will be removed from the stack only when the right sub-tree has been visited.so the path will be stored in the stack. we ca
sjames
NORMAL
2014-07-28T03:16:52+00:00
2018-10-12T15:32:40.437983+00:00
24,779
false
In the postorder traversal, the node will be removed from the stack only when the right sub-tree has been visited.so the path will be stored in the stack. we can keep check the SUM, the length from root to leaf node.\nat leaf node, if SUM == sum, OK, return true. After postorder traversal, return false.\n\nI have compa...
75
2
['Iterator']
20
path-sum
✅C++ || BEATS 95% || EASY || EXPLAINED || OPTIMIZED
c-beats-95-easy-explained-optimized-by-a-sojx
PLEASE UPVOTE IF YOU FIND MY APPROACH HELPFUL, MEANS A LOT \uD83D\uDE0A\n\nQues) Why we return left || right ???\nAns => return left || right means we are check
ayushsenapati123
NORMAL
2022-10-04T04:25:35.632590+00:00
2022-10-04T04:34:03.673033+00:00
7,039
false
**PLEASE UPVOTE IF YOU FIND MY APPROACH HELPFUL, MEANS A LOT \uD83D\uDE0A**\n\n**Ques)** Why we `return left || right` ???\n**Ans =>** `return left || right` means we are checking either root->left side gives us our targetSum or root->right side gives us our targetSum\n\n```\nclass Solution {\npublic:\n bool hasPath...
74
0
['Tree', 'Recursion', 'C++']
3
path-sum
My java no-recursive method
my-java-no-recursive-method-by-scott-mhrg
the idea is preorder traverse , instead of using recursive call, I am using a stack.\nthe only problem is that I changed TreeNode value\n\n public boolean ha
scott
NORMAL
2015-01-17T05:12:26+00:00
2018-09-20T06:13:09.864089+00:00
13,788
false
the idea is preorder traverse , instead of using recursive call, I am using a stack.\nthe only problem is that I changed TreeNode value\n\n public boolean hasPathSum(TreeNode root, int sum) {\n \t Stack <TreeNode> stack = new Stack<> ();\t \n \t stack.push(root) ;\t \n \t while (!stack.isEmpt...
65
1
[]
6
path-sum
Simplest C++ solution. EASY to understand.
simplest-c-solution-easy-to-understand-b-v2v1
\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int targetSum)\n {\n if(root == NULL)\n {\n return false;\n
kfaisal-se
NORMAL
2021-06-20T10:10:57.652991+00:00
2021-06-20T10:10:57.653033+00:00
6,087
false
```\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int targetSum)\n {\n if(root == NULL)\n {\n return false;\n }\n if(root->left == NULL && root->right == NULL && root->val - targetSum == 0)\n {\n return true;\n }\n \n boo...
56
2
['Recursion', 'C', 'C++']
2
path-sum
One Line Solution Sharing in Javascript
one-line-solution-sharing-in-javascript-f95vu
Since this problem is quite straight forward, so I played around a bit and turned it into the shortest solution as below.\n\n /*\n * Memo:\n * Comple
imcoddy
NORMAL
2015-06-02T12:22:35+00:00
2015-06-02T12:22:35+00:00
5,304
false
Since this problem is quite straight forward, so I played around a bit and turned it into the shortest solution as below.\n\n /**\n * Memo:\n * Complex: O(n)\n * Runtime: 164ms\n * Tests: 114 test cases passed\n * Rank: A\n */\n var hasPathSum = function(root, sum) { return root ? (!root.l...
56
2
['Recursion', 'JavaScript']
7
path-sum
[Python] BFS, DFS (recursive), DFS (iterative) solution
python-bfs-dfs-recursive-dfs-iterative-s-wij7
I. DFS recursive solution\nAlgorithm:\n1. Visit a node and check that node is leaf and node.val == sum. If it\'s true - return True, else continue traverse\n2.
rgalyeon
NORMAL
2020-03-09T10:27:07.475788+00:00
2020-03-09T10:29:19.383990+00:00
5,329
false
#### I. DFS recursive solution\nAlgorithm:\n1. Visit a node and check that node is leaf and node.val == sum. If it\'s true - return True, else continue traverse\n2. Traverse the left subtree and decrease current sum by value of current node , i.e., call `hasPathSum(node.left, curr_sum - node.val)`\n3. Traverse the righ...
50
0
['Depth-First Search', 'Breadth-First Search', 'Python3']
1
path-sum
【Video】Using DFS.
video-using-dfs-by-niits-psag
IntuitionUsing DFS.Solution Video⭐️⭐️ Don't forget to subscribe to my channel! ⭐️⭐️■ Subscribe URL http://www.youtube.com/channel/UC9RMNwYTL3SXCP6ShLWVFww?sub_c
niits
NORMAL
2025-02-17T17:18:10.766084+00:00
2025-02-18T16:02:47.096493+00:00
4,807
false
# Intuition Using DFS. --- # Solution Video https://youtu.be/pAZ3HqA7awU ### ⭐️⭐️ Don't forget to subscribe to my channel! ⭐️⭐️ **■ Subscribe URL** http://www.youtube.com/channel/UC9RMNwYTL3SXCP6ShLWVFww?sub_confirmation=1 Subscribers: 14,550 Thank you for your support! --- # Approach ![スクリーンショット 2025-02-18 1....
44
0
['Tree', 'Depth-First Search', 'Binary Tree', 'C++', 'Java', 'Python3', 'JavaScript']
0
path-sum
Easy, 5 Lines and Clean Java Solution
easy-5-lines-and-clean-java-solution-by-exb7h
You simply check if current node (starting with root) is a leaf node and sum is equal its value. If not, you just check left or right with the decremented sum.
berkayk
NORMAL
2016-03-05T20:40:54+00:00
2016-03-05T20:40:54+00:00
6,883
false
You simply check if current node (starting with root) is a leaf node and sum is equal its value. If not, you just check left or right with the decremented sum. If one of them returns true, it has a path.\n\n public boolean hasPathSum(TreeNode root, int sum) { \n if (root == null)\n return false;\n...
42
0
['Java']
5
path-sum
A Java Concise solution
a-java-concise-solution-by-mostafa2-dkhk
public boolean hasPathSum(TreeNode root, int sum) {\n if(root == null){\n\t return false;\n\t }\n if(root.left == null && root.right == null){
mostafa2
NORMAL
2015-06-06T15:01:28+00:00
2015-06-06T15:01:28+00:00
11,910
false
public boolean hasPathSum(TreeNode root, int sum) {\n if(root == null){\n\t return false;\n\t }\n if(root.left == null && root.right == null){\n\t return (root.val == sum);\n\t }\n\t return hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val);\n \t \n ...
40
0
[]
5
path-sum
✅ 🔥 0 ms Runtime Beats 100% User🔥|| Code Idea ✅ || Algorithm & Solving Step ✅ ||
0-ms-runtime-beats-100-user-code-idea-al-cdb6
\n\n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n### Intuition :\nThe problem requires checking if there is a root-to-leaf path in a
Letssoumen
NORMAL
2024-12-04T00:12:57.040857+00:00
2024-12-04T00:12:57.040893+00:00
5,717
false
![Screenshot 2024-12-04 at 5.36.20\u202FAM.png](https://assets.leetcode.com/users/images/8715fb43-f031-4150-ba06-71f6d558de30_1733270844.0401592.png)\n\n\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE AT THE END \u2705 :\n\n### **Intuition** :\nThe problem requires checking if there is a **root-to-leaf path** in a bin...
39
0
['Tree', 'Depth-First Search', 'Breadth-First Search', 'Binary Tree', 'C++', 'Java', 'Python3']
0
path-sum
C++ || Efficient|| Recursive|| Easy || 3 lines || Solution ||with comments ||
c-efficient-recursive-easy-3-lines-solut-e48l
If you understand the approach please please upvote!!!\nThanks :)\n```\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int targetSum) {\n
Debajyoti-Shit
NORMAL
2022-02-06T06:04:56.144751+00:00
2022-02-06T06:04:56.144795+00:00
2,828
false
#### If you understand the approach please please upvote!!!\n***Thanks :)***\n```\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int targetSum) {\n if(root==NULL) return false;\n \n //we reached here,i.e the root is not NULL, so we took the root value in our sum, and remaining targ...
39
1
['Depth-First Search', 'Breadth-First Search', 'Recursion', 'C', 'C++']
1
path-sum
Java ||Three Easy Approach With Explanation || Preorder || Postorder || 0ms
java-three-easy-approach-with-explanatio-5j4o
\n1 st Approach \nclass Solution\n{\n public boolean hasPathSum(TreeNode root, int targetSum)//we always try to approach the zero ----0++++ from any half lef
swapnilGhosh
NORMAL
2021-07-10T17:20:00.799065+00:00
2022-01-02T19:07:18.353304+00:00
2,282
false
```\n1 st Approach \nclass Solution\n{\n public boolean hasPathSum(TreeNode root, int targetSum)//we always try to approach the zero ----0++++ from any half left or right, like taking limit//if zero found at leaf then true else false\n {\n if(root == null)\n return false;//base case when the sel...
36
0
['Depth-First Search', 'Recursion', 'Java']
4
path-sum
✅Accepted| | ✅Easy solution || ✅Short & Simple || ✅Best Method
accepted-easy-solution-short-simple-best-u0da
\n# Code\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(
sanjaydwk8
NORMAL
2023-01-15T12:02:14.745915+00:00
2023-01-15T12:02:14.745952+00:00
5,117
false
\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeN...
31
0
['C++']
1
path-sum
My Python iterative DFS solution
my-python-iterative-dfs-solution-by-clue-qsz8
\n def hasPathSum(self, root, sum):\n if root is None:\n return False\n stack = [(root, sum)]\n while stack:\n nod
clue
NORMAL
2014-11-17T01:58:23+00:00
2014-11-17T01:58:23+00:00
6,517
false
\n def hasPathSum(self, root, sum):\n if root is None:\n return False\n stack = [(root, sum)]\n while stack:\n node, _sum = stack.pop()\n if node.left is node.right is None and node.val == _sum:\n return True\n if node.left:\n ...
29
0
['Python']
5
path-sum
[C++] 97% Runtime Iterative and Recursive Solution
c-97-runtime-iterative-and-recursive-sol-pnft
Iterative Solution \n\nbool hasPathSum(TreeNode* root, int sum) {\n if(root == NULL) return false;\n stack<pair<TreeNode*,int>> stack;\n st
hunarbatra
NORMAL
2020-02-23T19:37:09.726500+00:00
2020-02-23T19:37:09.726541+00:00
2,924
false
Iterative Solution \n```\nbool hasPathSum(TreeNode* root, int sum) {\n if(root == NULL) return false;\n stack<pair<TreeNode*,int>> stack;\n stack.push({root, root->val});\n while(!stack.empty()) {\n TreeNode* current = stack.top().first; \n int total_sum = stack.top().s...
25
0
['Recursion', 'C', 'Iterator', 'C++']
2
path-sum
Python Elegant & Short | DFS
python-elegant-short-dfs-by-kyrylo-ktl-5seh
\nclass Solution:\n """\n Time: O(n)\n Memory: O(n)\n """\n\n def hasPathSum(self, root: Optional[TreeNode], target: int) -> bool:\n if
Kyrylo-Ktl
NORMAL
2022-10-04T07:17:55.317103+00:00
2022-10-04T07:17:55.317142+00:00
2,483
false
```\nclass Solution:\n """\n Time: O(n)\n Memory: O(n)\n """\n\n def hasPathSum(self, root: Optional[TreeNode], target: int) -> bool:\n if root is None:\n return False\n if root.left is None and root.right is None:\n return target == root.val\n return self.has...
24
0
['Depth-First Search', 'Python', 'Python3']
0
path-sum
Python solution
python-solution-by-zitaowang-2fa0
Recursion:\n\nclass Solution(object):\n def hasPathSum(self, root, sum):\n """\n :type root: TreeNode\n :type sum: int\n :rtype:
zitaowang
NORMAL
2018-09-14T03:12:50.114055+00:00
2018-10-01T23:40:49.345775+00:00
3,333
false
Recursion:\n```\nclass Solution(object):\n def hasPathSum(self, root, sum):\n """\n :type root: TreeNode\n :type sum: int\n :rtype: bool\n """\n if not root:\n return False\n elif not root.left and not root.right:\n if root.val == sum:\n ...
23
1
[]
4
path-sum
🔥 [LeetCode The Hard Way] 🔥 Explained Line By Line
leetcode-the-hard-way-explained-line-by-6yw6b
Please check out LeetCode The Hard Way for more solution explanations and tutorials. \nI\'ll explain my solution line by line daily and you can find the full li
__wkw__
NORMAL
2022-10-04T03:40:39.029283+00:00
2022-10-04T03:40:39.029350+00:00
1,666
false
Please check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. \nI\'ll explain my solution line by line daily and you can find the full list in my [Discord](https://discord.gg/Nqm4jJcyBf).\nIf you like it, please give a star, watch my [Github R...
21
1
['Recursion', 'C', 'C++']
7
path-sum
3-line Java Solution
3-line-java-solution-by-dummyshooter-lq4r
\n public boolean hasPathSum(TreeNode root, int sum) {\n if (root == null) return false;\n if (root.left == null && root.right == null && root.
dummyshooter
NORMAL
2016-04-08T15:19:46+00:00
2016-04-08T15:19:46+00:00
2,324
false
\n public boolean hasPathSum(TreeNode root, int sum) {\n if (root == null) return false;\n if (root.left == null && root.right == null && root.val == sum) return true;\n return hasPathSum(root.left, sum - root.val) || hasPathSum(root.right, sum - root.val);\n }
20
0
['Recursion', 'Java']
0
path-sum
JAVASCRIPT || EASY CODE || THUMBS UP IF YOU LIKE ❤️
javascript-easy-code-thumbs-up-if-you-li-2oz5
\n# Code\n\n\nvar hasPathSum = function (root, targetSum) {\n if (!root)\n return false\n if (root.val === targetSum && (!root.left && !root.right)
sikkasakshi2
NORMAL
2022-12-11T19:20:51.534075+00:00
2022-12-11T19:20:51.534114+00:00
1,835
false
\n# Code\n```\n\nvar hasPathSum = function (root, targetSum) {\n if (!root)\n return false\n if (root.val === targetSum && (!root.left && !root.right))\n return true\n\n return hasPathSum(root.left, targetSum - root.val) || hasPathSum(root.right, targetSum - root.val)\n\n};\n```
18
0
['JavaScript']
5
path-sum
C++ DFS - Multiple Solutions
c-dfs-multiple-solutions-by-aishvaryarat-5nx2
\nSolution 1: \nclass Solution {\npublic:\n \n int pathSum = 0; \n bool pathFound = false;\n \n bool hasPathSum(TreeNode* root, int targetSum) \n
aishvaryarathore
NORMAL
2021-06-06T20:20:11.842329+00:00
2021-07-07T23:21:39.990307+00:00
1,449
false
```\nSolution 1: \nclass Solution {\npublic:\n \n int pathSum = 0; \n bool pathFound = false;\n \n bool hasPathSum(TreeNode* root, int targetSum) \n { \n if(root != NULL)\n {\n pathSum += root->val;\n \n if(root->left == NULL && root->right...
18
0
['Depth-First Search', 'C']
3
path-sum
\u3010Python\u3011Recursive solution with explanation and thinking process
u3010pythonu3011recursive-solution-with-p8gie
Base case\n1. This question wants to find a path from node to the leaf, so the node who satisfies must be a leaf (not node.left and not nood.right)\n2. I want t
xiaohk
NORMAL
2016-06-09T15:36:09+00:00
2016-06-09T15:36:09+00:00
1,551
false
## Base case\n1. This question wants to find a path from node to the **leaf**, so the node who satisfies must be a **leaf** (`not node.left and not nood.right`)\n2. I want to recursively subtract the `sum` by current node's value, so the leaf node of correct path must have the same value of its assigned `sum`\n\n## Rec...
18
0
['Python']
1
path-sum
Very Easy || 100% || 3 Line || Explained (Java, C++, Python, JS, C, Python3)
very-easy-100-3-line-explained-java-c-py-ytj1
Java Solution:\nRuntime: 0 ms, faster than 100.00% of Java online submissions for Path Sum.\n\nclass Solution {\n public boolean hasPathSum(TreeNode root, in
PratikSen07
NORMAL
2022-08-16T07:03:31.701021+00:00
2022-08-16T12:16:56.958267+00:00
3,151
false
# **Java Solution:**\nRuntime: 0 ms, faster than 100.00% of Java online submissions for Path Sum.\n```\nclass Solution {\n public boolean hasPathSum(TreeNode root, int targetSum) {\n // If the tree is empty i.e. root is NULL, return false...\n\t if (root == null) return false;\n // If there is only ...
17
0
['Recursion', 'C', 'Python', 'Java', 'Python3', 'JavaScript']
2
path-sum
🌺C#, Java, Python3, JavaScript Solution - O(n)
c-java-python3-javascript-solution-on-by-lu2s
Here to see the full explanation :\u2B50Zyrastory - #112 Path Sum\u2B50\n\n\n---\n\nWe can use a simple recursive approach and leverage DFS to traverse a binary
Daisy001
NORMAL
2023-10-09T01:08:11.486304+00:00
2023-10-09T01:11:22.491596+00:00
2,173
false
**Here to see the full explanation :\u2B50[Zyrastory - #112 Path Sum](https://zyrastory.com/en/coding-en/leetcode-en/leetcode-112-path-sum-solution-and-explanation-en/)\u2B50**\n\n\n---\n\nWe can use a simple recursive approach and leverage DFS to traverse a binary tree.\n\nThis algorithm is quite efficient because it ...
16
0
['Java', 'Python3', 'JavaScript', 'C#']
0
path-sum
Path Sum with step by step explanation
path-sum-with-step-by-step-explanation-b-u1jj
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nThis solution uses an iterative approach with a stack to traverse the bin
Marlen09
NORMAL
2023-02-16T12:07:12.684425+00:00
2023-02-16T12:07:12.684463+00:00
3,310
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nThis solution uses an iterative approach with a stack to traverse the binary tree and keep track of the current path value. It checks if the current node is a leaf node and its value matches the target sum. If not, it adds t...
16
0
['Tree', 'Depth-First Search', 'Breadth-First Search', 'Python', 'Python3']
0
path-sum
JAVA || Easy Solution || 2 Liner Code.|| Recursive
java-easy-solution-2-liner-code-recursiv-bisx
\tPLEASE UPVOTE IF YOU LIKE.\n\npublic class Solution {\n public boolean hasPathSum(TreeNode root, int sum) {\n if(root==null)return false;\n s
shivrastogi
NORMAL
2022-10-04T04:42:56.189162+00:00
2022-10-04T04:42:56.189201+00:00
1,354
false
\tPLEASE UPVOTE IF YOU LIKE.\n```\npublic class Solution {\n public boolean hasPathSum(TreeNode root, int sum) {\n if(root==null)return false;\n sum = sum - root.val;\n if(root.left==null && root.right==null){\n if(sum == 0)return true;\n else return false;\n }\n ...
16
0
['Recursion', 'Java']
3
path-sum
✔️ 100% Fastest Swift Solution
100-fastest-swift-solution-by-sergeylesc-ykna
\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right
sergeyleschev
NORMAL
2022-04-09T06:03:14.938261+00:00
2022-04-09T06:03:14.938295+00:00
838
false
```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * public var val: Int\n * public var left: TreeNode?\n * public var right: TreeNode?\n * public init() { self.val = 0; self.left = nil; self.right = nil; }\n * public init(_ val: Int) { self.val = val; self.left = nil; sel...
16
0
['Swift']
1
path-sum
[Python] simple DFS
python-simple-dfs-by-qsmy41-ssx9
\ndef hasPathSum(self, root: TreeNode, sum: int) -> bool:\n if not root: # edge case\n return False\n if not root.left and not root.right: \n
qsmy41
NORMAL
2020-08-08T12:27:41.614222+00:00
2020-08-08T12:27:41.614255+00:00
1,745
false
```\ndef hasPathSum(self, root: TreeNode, sum: int) -> bool:\n if not root: # edge case\n return False\n if not root.left and not root.right: \n return sum == root.val\n return self.hasPathSum(root.left, sum - root.val) or self.hasPathSum(root.right, sum - root.val)\n```
16
0
['Depth-First Search', 'Recursion', 'Python3']
2
path-sum
JAVA 100% FASTER SOLUTION🚀🚀 || STEP BY STEP EXPLAINED😉
java-100-faster-solution-step-by-step-ex-4lvy
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
abhiyadav05
NORMAL
2023-07-15T11:36:20.173486+00:00
2023-07-15T11:37:33.674692+00:00
1,633
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$...
15
0
['Tree', 'Binary Tree', 'Java']
2
path-sum
Path Sum || 99.22% FASTEST EXECUTION || C++ || 3 LINE EASY SOLUTION || SIMPLE AND SHORT
path-sum-9922-fastest-execution-c-3-line-xbhn
SHIVAM DAILY LEETCODE SOLUTIONS || CHECK : https://bit.ly/leetcode-solutions\nRuntime: 4 ms, faster than 99.22% of C++ online submissions for Path Sum.\nMemory
shivambit
NORMAL
2022-10-04T05:51:40.536899+00:00
2022-10-04T05:51:40.536934+00:00
2,066
false
**SHIVAM DAILY LEETCODE SOLUTIONS || CHECK : [https://bit.ly/leetcode-solutions](https://bit.ly/leetcode-solutions)\nRuntime: 4 ms, faster than 99.22% of C++ online submissions for Path Sum.\nMemory Usage: 21.4 MB, less than 38.76% of C++ online submissions for Path Sum.** \n\n```\nclass Solution {\npublic:\n bool h...
15
1
['Recursion', 'C', 'C++']
4
path-sum
Easy JS Solution
easy-js-solution-by-hbjorbj-wg59
\n/*\n1. Use DFS to try all possible paths.\n2. Keep track of the sum of path during traversal. When leaf node is reached, check if\nthe sum of path equals the
hbjorbj
NORMAL
2021-05-14T01:02:40.862798+00:00
2021-05-14T01:05:23.141879+00:00
2,182
false
```\n/*\n1. Use DFS to try all possible paths.\n2. Keep track of the sum of path during traversal. When leaf node is reached, check if\nthe sum of path equals the target. If so, return true, else continue DFS traversal to\ntry other paths.\n*/\nvar hasPathSum = function(root, targetSum) {\n return dfs(root, targetSu...
14
0
['JavaScript']
1
path-sum
Python | Recursive approach | Easy to Solve
python-recursive-approach-easy-to-solve-p4uv7
Think about one small tree. Let say we have only one node like\n\n\t\t\t\t\t 1\n\t\t\t\tNone None\n\nand targetSum is 1, so our condtion will be \n\n
vsahoo
NORMAL
2021-05-04T06:38:30.046134+00:00
2021-05-05T05:33:57.542359+00:00
1,030
false
Think about one small tree. Let say we have only one node like\n```\n\t\t\t\t\t 1\n\t\t\t\tNone None\n```\nand targetSum is 1, so our condtion will be \n```\nif root.left is None and root.right is None and root.val == targetSum:\n return True\n```\n \n 1\n\t\t\t\t2 3\n...
14
0
['Recursion', 'Python']
2
path-sum
C++ Solution, recursion + Iterative-dfs + Iterative-bfs
c-solution-recursion-iterative-dfs-itera-4lhg
\nclass Solution {\n public:\n bool hasPathSum(TreeNode* root, int sum) {\n if (not root) return false;\n sum -= root->val;\n if (not root->left and n
saravanakumar_dharmaraj
NORMAL
2020-07-19T16:46:37.225742+00:00
2020-07-19T21:31:12.449413+00:00
836
false
```\nclass Solution {\n public:\n bool hasPathSum(TreeNode* root, int sum) {\n if (not root) return false;\n sum -= root->val;\n if (not root->left and not root->right) {\n return sum == 0;\n }\n return hasPathSum(root->left, sum) || hasPathSum(root->right, sum);\n }\n};\n```\n//DFS\n```\nclass So...
14
0
['C']
0
path-sum
Video Solution | Intuition Explained | C++
video-solution-intuition-explained-c-by-uahn0
Video\nHey everyone, i have craeted a video solution for this problem where we discuss intuition for this problem, this video is part of my trees playlist and b
_code_concepts_
NORMAL
2024-07-24T09:48:26.429800+00:00
2024-07-27T09:45:19.716997+00:00
1,385
false
# Video\nHey everyone, i have craeted a video solution for this problem where we discuss intuition for this problem, this video is part of my trees playlist and belongs to category "Root to leaf path".\n\nVideo link: https://youtu.be/6t-dWQSM-nw\nPlaylist link: https://www.youtube.com/playlist?list=PLICVjZ3X1Aca0TjUTcs...
13
0
['C++']
0
path-sum
C++ solutions
c-solutions-by-infox_92-zf8o
\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int sum) {\n if(!root)return false; //Terminatin
Infox_92
NORMAL
2022-11-10T06:34:42.707269+00:00
2022-11-10T06:34:42.707304+00:00
1,971
false
```\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int sum) {\n if(!root)return false; //Terminating Condition\n sum=sum-root->val; //Body\n if(sum==0&&!root->left&&!root->right)return true; ...
13
0
['C', 'C++']
0
path-sum
Share my 3 lines c++ solution
share-my-3-lines-c-solution-by-yhxdl-63n9
/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n *
yhxdl
NORMAL
2015-10-08T07:28:20+00:00
2015-10-08T07:28:20+00:00
2,387
false
/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n class Solution {\n public:\n bool hasPathSum(TreeNode* root, int ...
13
1
[]
2
path-sum
solution
solution-by-mikhmanoff-oxzm
The function hasPathSum checks if there is a path from the root to the leaves in the binary tree defined by the root, whose sum of vertex values is equal to the
mikhmanoff
NORMAL
2023-05-04T22:30:24.879494+00:00
2023-05-04T22:30:24.879535+00:00
3,260
false
The function hasPathSum checks if there is a path from the root to the leaves in the binary tree defined by the root, whose sum of vertex values is equal to the given number targetSum.\n\nThe function first checks if the root is empty. If it is empty, the function returns false, since an empty tree has no path from the...
12
0
['Python', 'Java', 'Go', 'Python3', 'C#']
2
path-sum
JavaScript Solution: 98.32%
javascript-solution-9832-by-voltaaage-84si
\nvar hasPathSum = function(root, sum) {\n return dfs(root, 0, sum);\n};\n\nvar dfs = function(curr, currentSum, targetSum) {\n if (!curr) {\n retu
voltaaage
NORMAL
2020-02-23T09:07:02.009954+00:00
2020-02-23T09:07:02.009988+00:00
2,874
false
```\nvar hasPathSum = function(root, sum) {\n return dfs(root, 0, sum);\n};\n\nvar dfs = function(curr, currentSum, targetSum) {\n if (!curr) {\n return false;\n }\n\n currentSum += curr.val;\n \n if (curr.left === null && curr.right === null) {\n return currentSum === targetSum;\n }\...
12
0
['JavaScript']
2
path-sum
4 ms C Solution ( Recursion )
4-ms-c-solution-recursion-by-rachelwang0-1d3u
bool hasPathSum(struct TreeNode* root, int sum) {\n if (!root) \n return false;\n if (!root->right && !root->left) \n return
rachelwang0831
NORMAL
2015-05-22T06:53:07+00:00
2015-05-22T06:53:07+00:00
1,304
false
bool hasPathSum(struct TreeNode* root, int sum) {\n if (!root) \n return false;\n if (!root->right && !root->left) \n return sum==root->val;\n return hasPathSum(root->left, sum-root->val)||hasPathSum(root->right, sum-root->val);\n }
12
0
[]
0
path-sum
💢☠💫Easiest👾Faster✅💯 Lesser🧠 🎯 C++✅Python3🐍✅Java✅C✅Python🐍✅C#✅💥🔥💫Explained☠💥🔥 Beats 100
easiestfaster-lesser-cpython3javacpython-z5hx
Intuition\n\n Describe your first thoughts on how to solve this problem. \n- JavaScript Code --> https://leetcode.com/problems/path-sum/submissions/1381986930\n
Edwards310
NORMAL
2024-09-07T11:20:24.453547+00:00
2024-09-07T11:20:24.453569+00:00
2,423
false
# Intuition\n![0ehh83fsnh811.jpg](https://assets.leetcode.com/users/images/0da4ecc3-6955-44fa-919d-0e5e412ce35f_1725707694.3144276.jpeg)\n<!-- Describe your first thoughts on how to solve this problem. -->\n- ***JavaScript Code -->*** https://leetcode.com/problems/path-sum/submissions/1381986930\n- ***C++ Code -->*** h...
11
0
['Tree', 'Depth-First Search', 'Breadth-First Search', 'C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript', 'C#']
1
path-sum
(✓) 💯 ACCEPTED | 3 LINE CODE | BEATS 100% | JAVA CODE | FASTEST Solution
accepted-3-line-code-beats-100-java-code-ixop
Path Sum\n##### 1) If the tree is empty then false\n##### 2) If there aren\'t any leaf node then return root == k if equal then true else false\n##### 3) And fi
efety
NORMAL
2024-02-28T17:35:04.315121+00:00
2024-02-28T17:35:04.315151+00:00
1,980
false
# Path Sum\n##### 1) If the tree is empty then false\n##### 2) If there aren\'t any leaf node then return root == k if equal then true else false\n##### 3) And finally we find the sum from either left or right node. \n##### 4) Here we subtract each value of those nodes from k thus eventually setp 2 will occur.\n<br><br...
11
0
['Java']
0
path-sum
Recursive depth-first traversal with sum calculation
recursive-depth-first-traversal-with-sum-5x7p
Intuition\n Describe your first thoughts on how to solve this problem. \nWe need to traverse the tree in a depth-first manner, keeping track of the sum of value
Rare_Zawad
NORMAL
2023-02-17T18:07:13.950854+00:00
2023-02-17T18:07:13.950893+00:00
2,010
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe need to traverse the tree in a depth-first manner, keeping track of the sum of values along the path from the root to the current node. When we reach a leaf node, we check if the sum is equal to the target sum. If yes, we return true, ...
11
0
['Tree', 'Depth-First Search', 'Breadth-First Search', 'Binary Tree', 'Python3']
4
path-sum
C++ || 2 different approach || recursive / iterative
c-2-different-approach-recursive-iterati-pv03
I came up with 2 different approaches for this problem. Please let me know if you have other ideas or if you have suggestions on how to improve one of the solut
heder
NORMAL
2022-10-04T20:28:13.963202+00:00
2022-10-09T17:57:34.016829+00:00
1,622
false
I came up with 2 different approaches for this problem. Please let me know if you have other ideas or if you have suggestions on how to improve one of the solutions. This problem many good solutions have been posted already, nevertheless I just had fun writing up my thoughts. So here we go. :)\n\n\n### Approach 1: recu...
11
0
['Recursion', 'C', 'Iterator']
1
path-sum
Simple JS Solution w/ Comments
simple-js-solution-w-comments-by-qkrrbtj-ah5c
\nconst hasPathSum = (root, targetSum) => {\n\tif (!root) return false;\n\n\tlet output = false;\n\tconst traverse = (root, sum = 0) => {\n\t\t// if targetSum e
qkrrbtjd90
NORMAL
2022-03-17T00:49:25.116756+00:00
2022-05-10T17:47:06.953701+00:00
627
false
```\nconst hasPathSum = (root, targetSum) => {\n\tif (!root) return false;\n\n\tlet output = false;\n\tconst traverse = (root, sum = 0) => {\n\t\t// if targetSum exist at end of path, set output to TRUE\n\t\tif (!root.left && !root.right) {\n\t\t\tif (targetSum === sum + root.val) output = true;\n\t\t}\n\n\t\t// traver...
11
0
['Depth-First Search', 'JavaScript']
2
path-sum
Java Solution, 0 ms, Beats 100%
java-solution-0-ms-beats-100-by-abstract-aywl
Java Code\n\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * Tree
abstractConnoisseurs
NORMAL
2023-02-21T05:00:31.326056+00:00
2023-02-21T05:00:31.326097+00:00
2,727
false
# Java Code\n```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * ...
10
0
['Tree', 'Depth-First Search', 'Breadth-First Search', 'Binary Tree', 'Java']
1
path-sum
Java Recursive Solution
java-recursive-solution-by-kadamyogesh72-i0oj
\nclass Solution {\n public boolean hasPathSum(TreeNode root, int targetSum) {\n if(root==null){\n return false;\n }\n \n
kadamyogesh7218
NORMAL
2022-10-04T05:11:34.050964+00:00
2022-10-04T05:11:34.051013+00:00
968
false
```\nclass Solution {\n public boolean hasPathSum(TreeNode root, int targetSum) {\n if(root==null){\n return false;\n }\n \n if(root.left==null && root.right==null && targetSum==root.val){\n return true;\n }\n \n return hasPathSum(root.left,targe...
10
0
['Depth-First Search', 'Recursion', 'Binary Tree', 'Java']
0
path-sum
Three solution to come up on iterview - easy to understand
three-solution-to-come-up-on-iterview-ea-8km8
Hey there! This problem gives us to practice in use of different binary tree traversals. If you look closer to the idea of the problem you will come up with the
floatfoo
NORMAL
2022-07-16T20:07:21.426211+00:00
2022-07-16T20:07:21.426254+00:00
629
false
Hey there! This problem gives us to practice in use of different binary tree traversals. If you look closer to the idea of the problem you will come up with the following: DFS (**preorder**) with recursion, DFS iterative version and BFS (or level traversal). Go ahead and get to know all of them.\n\n___\n***DFS recursio...
10
0
['Breadth-First Search', 'Recursion', 'Iterator', 'Java']
1
path-sum
Java || 100% Faster || Recursion
java-100-faster-recursion-by-sherriecao-4836
Please upvote if it helps! Thx :D\n\npublic boolean hasPathSum(TreeNode root, int targetSum) {\n\tif (root == null) return false;\n\tif (root.left == null && ro
SherrieCao
NORMAL
2021-12-29T07:37:20.477737+00:00
2021-12-29T07:37:20.477780+00:00
711
false
## Please upvote if it helps! Thx :D\n```\npublic boolean hasPathSum(TreeNode root, int targetSum) {\n\tif (root == null) return false;\n\tif (root.left == null && root.right==null && root.val == targetSum) return true;\n\ttargetSum -= root.val;\n\treturn hasPathSum(root.left, targetSum) || hasPathSum(root.right, targe...
10
0
['Recursion', 'Java']
1
path-sum
[Python3] recursively and iteratively
python3-recursively-and-iteratively-by-z-kbvh
recursively:\n\nclass Solution:\n def hasPathSum(self, root: TreeNode, sum: int) -> bool:\n if not root:\n return False\n sum -= roo
zhanweiting
NORMAL
2019-08-03T23:10:48.131673+00:00
2019-08-03T23:18:27.180808+00:00
1,659
false
recursively:\n```\nclass Solution:\n def hasPathSum(self, root: TreeNode, sum: int) -> bool:\n if not root:\n return False\n sum -= root.val\n if not root.left and not root.right:\n return sum == 0\n return self.hasPathSum(root.left,sum) or self.hasPathSum(root.right...
10
0
['Python', 'Python3']
0
path-sum
Python3 deque beat 98.10% 34ms
python3-deque-beat-9810-34ms-by-amitpand-js6w
\n\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n)
amitpandit03
NORMAL
2023-03-24T17:26:23.586818+00:00
2023-03-24T17:26:23.586857+00:00
5,669
false
\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n# Definition for a binary tree node.\n# class TreeNode:\n# def __init__(self, val=0, left=None, right=None):\n# ...
9
0
['Tree', 'Depth-First Search', 'Breadth-First Search', 'Binary Tree', 'Python3']
1
path-sum
1-line Python
1-line-python-by-alex391a-nvwr
\nclass Solution:\n def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool:\n return (root.val == targetSum) if (root and not root.lef
alex391a
NORMAL
2022-10-04T05:52:17.831334+00:00
2022-10-19T09:10:53.141071+00:00
1,117
false
```\nclass Solution:\n def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool:\n return (root.val == targetSum) if (root and not root.left and not root.right) else (root and (self.hasPathSum(root.right, targetSum - root.val) or self.hasPathSum(root.left, targetSum - root.val)))\n```
9
0
['Python3']
1
path-sum
Python 3 || 7 lines, recursion || T/S: 85% / 86%
python-3-7-lines-recursion-ts-85-86-by-s-3bqa
\nclass Solution:\n def hasPathSum(self, root: TreeNode, targetSum: int) -> bool:\n \n if not root :
Spaulding_
NORMAL
2022-10-04T00:27:03.971132+00:00
2024-05-26T20:35:06.720121+00:00
388
false
```\nclass Solution:\n def hasPathSum(self, root: TreeNode, targetSum: int) -> bool:\n \n if not root : # if null node\n return False # return False\n \n if (not root.right and not root.left ...
9
0
['Recursion', 'Python']
1
path-sum
[C++] 100% Time, one-line recursive solution
c-100-time-one-line-recursive-solution-b-5545
The base case is when the root->val == sum and the node is a leaf (ie: both !root-left and !root->right are true); if not, we keep recursing with decreased valu
ajna
NORMAL
2020-06-16T18:38:44.494942+00:00
2020-06-16T18:38:44.494978+00:00
906
false
The base case is when the `root->val == sum` and the node is a leaf (ie: both `!root-left` and `!root->right` are true); if not, we keep recursing with decreased values of `sum`:\n\nNotice that since the nodes can also have negative values, there is no way to know in advance when you have summed "too much" and thus you...
9
1
['Recursion', 'C', 'C++']
1
path-sum
javaScript
javascript-by-suxiaohui1996-9myo
\nvar hasPathSum = function(root, sum) {\n if(!root) {\n return false;\n }\n if(!root.left && !root.right) {\n return root.val == sum ? t
suxiaohui1996
NORMAL
2020-02-28T09:19:23.905770+00:00
2020-02-28T09:19:23.905802+00:00
945
false
```\nvar hasPathSum = function(root, sum) {\n if(!root) {\n return false;\n }\n if(!root.left && !root.right) {\n return root.val == sum ? true : false;\n }\n let remain = sum - root.val\n return hasPathSum(root.left, remain) || hasPathSum(root.right, remain)\n};\n```
9
0
[]
0
path-sum
Java solution, shortest!!!
java-solution-shortest-by-erhu-aj12
public boolean hasPathSum(TreeNode root, int sum) {\n if (root == null) {\n return false;\n }\n\n if (sum - root.val == 0 && roo
erhu
NORMAL
2015-03-09T07:59:03+00:00
2015-03-09T07:59:03+00:00
1,596
false
public boolean hasPathSum(TreeNode root, int sum) {\n if (root == null) {\n return false;\n }\n\n if (sum - root.val == 0 && root.left == null && root.right == null) {\n return true;\n }\n\n return hasPathSum(root.left, sum - root.val) || hasPathSum(root.righ...
9
0
[]
0
path-sum
Share my easy and clean recursion Java solution with explanation
share-my-easy-and-clean-recursion-java-s-iart
public class Solution {\n public boolean hasPathSum(TreeNode root, int sum) {\n \n // check if root is null\n if(root ==
nlackx
NORMAL
2015-09-24T15:37:55+00:00
2015-09-24T15:37:55+00:00
989
false
public class Solution {\n public boolean hasPathSum(TreeNode root, int sum) {\n \n // check if root is null\n if(root == null) return false;\n \n // if the current node is not a leaf node, do recursion.\n if(root.left != null || root.right != ...
9
0
[]
0
path-sum
Java iterative solution with one stack
java-iterative-solution-with-one-stack-b-q2wq
\npublic boolean hasPathSum(TreeNode root, int sum) {\n Stack<TreeNode> visitedNodes = new Stack<>();\n TreeNode prev = null;\n \n wh
upthehell
NORMAL
2017-04-17T22:28:18.375000+00:00
2017-04-17T22:28:18.375000+00:00
764
false
```\npublic boolean hasPathSum(TreeNode root, int sum) {\n Stack<TreeNode> visitedNodes = new Stack<>();\n TreeNode prev = null;\n \n while(root!=null || !visitedNodes.isEmpty()){\n while(root!=null){\n visitedNodes.push(root);\n sum -= root.val;\n ...
9
0
[]
1
path-sum
✅💯🔥Simple Code🚀📌|| 🔥✔️Easy to understand🎯 || 🎓🧠Beats 100%🔥|| Beginner friendly💀💯
simple-code-easy-to-understand-beats-100-w2b7
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
atishayj4in
NORMAL
2024-08-01T20:11:08.270210+00:00
2024-08-01T20:11:08.270229+00:00
975
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
8
0
['Tree', 'Depth-First Search', 'Breadth-First Search', 'C', 'Binary Tree', 'Python', 'C++', 'Java']
0
path-sum
C++ and Python3 || DFS || Simple and Optimal
c-and-python3-dfs-simple-and-optimal-by-q3g9h
\n> \n\n# Code\nC++ []\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n *
meurudesu
NORMAL
2024-02-24T09:23:22.468875+00:00
2024-02-24T09:23:22.468897+00:00
2,268
false
> ![image.png](https://assets.leetcode.com/users/images/58094f43-11ac-4097-88f9-723310a2de8b_1708766547.1880958.png)\n> ![image.png](https://assets.leetcode.com/users/images/bd7a4684-8e75-4243-a2dc-de616943457e_1708766551.267105.png)\n\n# Code\n```C++ []\n/**\n * Definition for a binary tree node.\n * struct TreeNode {...
8
0
['Tree', 'Depth-First Search', 'Recursion', 'Binary Tree', 'C++', 'Python3']
1