일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- English
- Writing
- 화상영어
- 잡생각
- 링피트
- 만화도
- 영어원서읽기
- 10분
- 프로젝트
- FIT XR
- 월간
- 파비최
- 쓰릴오브파이트
- 리얼 클래스
- 운동
- realclass
- Daily Challenge
- 괜찮음
- 뭐든
- leetcode
- 개발자
- 3줄정리
- Problem Solving
- 읽기
- 매일
- 사이드
- 영어공부
- 30분
- 스탭퍼
- 미드시청
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/construct-string-from-binary-tree/
Construct String from Binary Tree - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
오늘도 트리 문제. Easy 난이도인데 쉬운지는 잘 모르겄다 =_=;
class Solution:
def tree2str(self, root: Optional[TreeNode]) -> str:
if not root:
return ''
output = str(root.val)
if root.left or root.right:
output += '(' + self.tree2str(root.left) + ')'
if root.right:
output += '(' + self.tree2str(root.right) + ')'
return output
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
Today's Challenge (0) | 2022.09.09 |
---|---|
Today's Challenge (0) | 2022.09.08 |
Today's Challenge (0) | 2022.09.06 |
Today's Challenge (0) | 2022.09.05 |
Today's Challenge (0) | 2022.09.04 |
Comments