목록전체 글 (5)
삼촌 공부
Question binary tree를 level별로 출력하되 출력하는 방향을 지그재그로 해라. level1일때는 오→왼, level2일때는 왼→오 이런식 Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its zigzag level order traversal as: [ [3], [20,9], [15,7] ..
Question binary tree에서 level별로 값을 출력하는 문제이다 Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its level order traversal as: [ [3], [9,20], [15,7] ] Answer # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None,..

Question 주어진 binary search tree가 유효한, 올바른 트리인지 판별하는 문제이다. Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left and right subtrees must also be binary search ..

Question leetcode 92번. unique binary search tree의 갯수를 구하는 문제 https://leetcode.com/problems/unique-binary-search-trees/ Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n? Example: Input: 3 Output: 5 Explanation: Given n = 3, there are a total of 5 unique BST's: 1 3 3 2 1 \ / / / \ \ 3 2 1 1 3 2 / / \ \ 2 1 2 3 Constraints: 1
92. Reverse Linked List II 2020-09-11 Question Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Example: Input: 1->2->3->4->5->NULL, m = 2, n = 4 Output: 1->4->3->2->5->NULL Answer # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: def reverseBetween(sel..