binary tree3 1372. Longest ZigZag Path in a Binary Tree - python https://leetcode.com/problems/longest-zigzag-path-in-a-binary-tree/description/ Longest ZigZag Path in a Binary Tree - LeetCode Can you solve this real interview question? Longest ZigZag Path in a Binary Tree - You are given the root of a binary tree. A ZigZag path for a binary tree is defined as follow: * Choose any node in the binary tree and a direction (right or left). * If the leetcode.com .. 2023. 4. 22. 103. Binary Tree Zigzag Level Order Traversal(Medium) Given the root of a binary tree, return the zigzag level order traversal of its nodes' values. (i.e., from left to right, then right to left for the next level and alternate between). root이진 트리가 주어 지면 노드 값의 지그재그 수준 순회를 반환합니다 . (즉, 왼쪽에서 오른쪽으로, 다음 레벨은 오른쪽에서 왼쪽으로 그리고 그 사이를 번갈아 가며). 이진 트리에서 한단계 내려갈때마다 왼쪽에서 오른쪽으로 출력 그 다음단계는 오른쪽에서 왼쪽으로 출력하는 문제 일단 한층씩 내려가면서 같은층 원소는 한 리스트에 넣어가면서 이중리스트를 만든다 그리고 홀수번째 리스트들.. 2023. 2. 19. 226. Invert Binary Tree (Easy) Given the root of a binary tree, invert the tree, and return its root. 이진 트리 가 주어 root지면 트리를 반전하고 루트를 반환합니다 . 주어진 이진트리 왼쪽과 오른쪽노드를 바꿔서 리턴하는 문제 매우 간단하다 한단계씩 내려가면서 왼쪽은노드는 오른쪽값으로 오른쪽 노드는 오른쪽값으로 바꿔주기만 하면 해결 # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def invertTree(s.. 2023. 2. 18. 이전 1 다음