코딩테스트76 [코딩테스트 연습] 행렬의 덧셈 ( zip 함수 ) # Problem 행렬의 덧셈은 행과 열의 크기가 같은 두 행렬의 같은 행, 같은 열의 값을 서로 더한 결과가 됩니다. 2개의 행렬 arr1과 arr2를 입력받아, 행렬 덧셈의 결과를 반환하는 함수, solution을 완성해주세요. 제한 조건 행렬 arr1, arr2의 행과 열의 길이는 500을 넘지 않습니다. 입출력 예 # My Answer def solution(arr1, arr2): answer = [] for i in range(len(arr1)): answer.append([]) for j in range(len(arr1[0])): answer[i].append(arr1[i][j] + arr2[i][j]) return answer # Solution 1 def sumMatrix(A,B): ans.. 2021. 5. 29. [LEET CODE] 215. Kth Largest Element in an Array # Problem Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Constraints: 1 int: return sorted(nums, reverse=True)[k - 1] # 힙 ( heap ) 최소힙 - 부모가 항상 자식보다 작거나 같다 ( 좌우 트리는 정렬된 구조는 아님) 최대힙 - 부모가 항상 자식보다 크거나 같다 거의 완전한 트리인 특수한 트리 기반 자료구조 우선순위 큐 구현 2021. 5. 26. [LEET CODE] 105. Construct Binary Tree from Preorder and Inorder Traversal # Problem Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the same tree, construct and return the binary tree. Constraints: 1 2021. 5. 24. [LEET CODE] 938. Range Sum of BST # Problem Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high]. Constraints: The number of nodes in the tree is in the range [1, 2 * 104]. 1 L: stack.append(node.left) if node.val < R: stack.append(node.right) if L L: stack.append(node.left) if node.val < R: stack.append(node.right) if L O.. 2021. 5. 24. [LEET CODE] 1038. Binary Search Tree to Greater Sum Tree # Problem Given the root of a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST. As a reminder, a binary search tree is a tree that satisfies these constraints: The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of.. 2021. 5. 24. [LEET CODE] 108. Convert Sorted Array to Binary Search Tree # Problem Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree. A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one. Constraints: 1 2021. 5. 19. 이전 1 ··· 5 6 7 8 9 10 11 ··· 13 다음 반응형