Pastebin
API
tools
faq
paste
Login
Sign up
SHARE
TWEET
miglss
42.YA
miglss
Apr 12th, 2025
442
0
Never
Add comment
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!
Python
0.53 KB
| None
|
0
0
raw
download
clone
embed
print
report
class
Solution:
def
lowestCommonAncestor
(
self
,
root:
'TreeNode'
,
p:
'TreeNode'
,
q:
'TreeNode'
)
-
>
'TreeNode'
:
def
dfs
(
root
)
:
if
root
in
(
None
,
p
,
q
)
:
return
root
left
=
dfs
(
root.
left
)
right
=
dfs
(
root.
right
)
if
left
and
right:
return
root
elif
left:
return
left
elif
right:
return
right
else
:
return
None
return
dfs
(
root
)
Advertisement
Add Comment
Please,
Sign In
to add comment
Public Pastes
✅ Method to get 13,000$ in 2 days
CSS | 49 min ago | 0.94 KB
✅ Free Money Exploit
CSS | 49 min ago | 0.94 KB
Untitled
1 hour ago | 10.48 KB
Untitled
3 hours ago | 11.62 KB
Untitled
5 hours ago | 16.92 KB
Untitled
7 hours ago | 20.31 KB
Untitled
11 hours ago | 6.74 KB
Untitled
13 hours ago | 8.95 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!
AltStyle
によって変換されたページ
(->オリジナル)
/
アドレス:
モード:
デフォルト
音声ブラウザ
ルビ付き
配色反転
文字拡大
モバイル