Coding Test
-
[프로그래머스] 주차 요금 계산 c++Coding Test/programmers 2022. 9. 27. 21:17
문제 설명 주차장의 요금표와 차량이 들어오고(입차) 나간(출차) 기록이 주어졌을 때, 차량별로 주차 요금을 계산하려고 합니다. 아래는 하나의 예시를 나타냅니다. 요금표 기본 시간(분) 기본 요금(원) 단위 시간(분) 단위 요금(원) 180 5000 10 600 입/출차 기록 시각(시:분) 차량 번호 내역 05:34 5961 입차 06:00 0000 입차 06:34 0000 출차 07:59 5961 출차 07:59 0148 입차 18:59 0000 입차 19:09 0148 출차 22:59 5961 입차 23:00 5961 출차 자동차별 주차 요금 차량 번호 누적 주차 시간(분) 주차 요금(원) 0000 34 + 300 = 334 5000 + ⌈(334 - 180) / 10⌉ x 600 = 14600 014..
-
[LeetCode] 897. Increasing Order Search Tree c++Coding Test/LeetCode 2022. 9. 27. 12:49
문제 Given the root of a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only one right child. 이진탐색트리의 값들을 node.right로 오름차순으로 정렬하는 문제이다. 주어진 이진탐색트리들은 node.left → node.val → node.right 순으로 값들이 오름차순으로 정렬되어 있다. 문제 해결 1. root노드의 left 먼저 탐색 2. 최하위 까지 탐색했다면 ans노드의 right에 root값을 저장 3. ans노드를 right로 ..
-
[LeetCode] 617. Merge Two Binary Trees c++Coding Test/LeetCode 2022. 9. 27. 11:10
문제 You are given two binary trees root1 and root2. Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge the two trees into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of t..
-
[LeetCode] 2331. Evaluate Boolean Binary Tree c++Coding Test/LeetCode 2022. 9. 26. 21:43
문제 You are given the root of a full binary tree with the following properties: Leaf nodes have either the value 0 or 1, where 0 represents False and 1 represents True. Non-leaf nodes have either the value 2 or 3, where 2 represents the boolean OR and 3 represents the boolean AND. The evaluation of a node is as follows: If the node is a leaf node, the evaluation is the value of the node, i.e. Tru..
-
[LeetCode] 938. Range Sum of BST c++Coding Test/LeetCode 2022. 9. 26. 18:11
문제 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]. 이진탐색트리의 node중에 low와 high사이에 있는 값을 모두 더한 값을 구하는 문제이다. 문제 해결 class Solution { public: int nSum = 0; int rangeSumBST(TreeNode* root, int low, int high) { if(root == NULL) return nSum; if(root->val >= low && root-> val val; } rangeSumBST..
-
[LeetCode] 1379. Find a Corresponding Node of a Binary Tree in a Clone of That Tree c++Coding Test/LeetCode 2022. 9. 26. 15:17
문제 Given two binary trees original and cloned and given a reference to a node target in the original tree. The cloned tree is a copy of the original tree. Return a reference to the same node in the cloned tree. Note that you are not allowed to change any of the two trees or the target node and the answer must be a reference to a node in the cloned tree. original 트리에 target노드를 찾는 문제이다. 문제 해결 Tree..