전체 글 240

[Greedy]99클럽 코테 스터디 21일차 TIL + 0561-array-partition

561. Array PartitionEasyGiven an integer array nums of 2n integers, group these integers into n pairs (a1, b1), (a2, b2), ..., (an, bn) such that the sum of min(ai, bi) for all i is maximized. Return the maximized sum. Example 1:Input: nums = [1,4,3,2]Output: 4Explanation: All possible pairings (ignoring the ordering of elements) are:1. (1, 4), (2, 3) -> min(1, 4) + min(2, 3) = 1 + 2 = 32. (1, 3..

[DP]99클럽 코테 스터디 20일차 TIL + 0119-pascals-triangle-ii

119. Pascal's Triangle IIEasyGiven an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it as shown: Example 1:Input: rowIndex = 3Output: [1,3,3,1]Example 2:Input: rowIndex = 0Output: [1]Example 3:Input: rowIndex = 1Output: [1,1] Constraints:0  Follow up: Could you optimize your algorith..

[Greedy]99클럽 코테 스터디 19일차 TIL + 프로그래머스/1/135808. 과일 장수

문제 설명과일 장수가 사과 상자를 포장하고 있습니다. 사과는 상태에 따라 1점부터 k점까지의 점수로 분류하며, k점이 최상품의 사과이고 1점이 최하품의 사과입니다. 사과 한 상자의 가격은 다음과 같이 결정됩니다.한 상자에 사과를 m개씩 담아 포장합니다.상자에 담긴 사과 중 가장 낮은 점수가 p (1 ≤ p ≤ k)점인 경우, 사과 한 상자의 가격은 p * m 입니다.과일 장수가 가능한 많은 사과를 팔았을 때, 얻을 수 있는 최대 이익을 계산하고자 합니다.(사과는 상자 단위로만 판매하며, 남는 사과는 버립니다)예를 들어, k = 3, m = 4, 사과 7개의 점수가 [1, 2, 3, 1, 2, 3, 1]이라면, 다음과 같이 [2, 3, 2, 3]으로 구성된 사과 상자 1개를 만들어 판매하여 최대 이익을 얻..

[DFS/BFS]99클럽 코테 스터디 18일차 TIL + 0933-increasing-order-search-tree

933. Increasing Order Search TreeEasyGiven 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. Example 1:Input: root = [5,3,6,2,4,null,8,1,null,null,null,7,9]Output: [1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9]Example 2:Input: root = [5,1,7]Out..

[DFS/BFS]99클럽 코테 스터디 17일차 TIL + 0094-binary-tree-inorder-traversal

94. Binary Tree Inorder TraversalEasyGiven the root of a binary tree, return the inorder traversal of its nodes' values. Example 1:Input: root = [1,null,2,3]Output: [1,3,2]Example 2:Input: root = []Output: []Example 3:Input: root = [1]Output: [1] Constraints:The number of nodes in the tree is in the range [0, 100].-100  Follow up: Recursive solution is trivial, could you do it iteratively?  : 35..

[Brute Force]99클럽 코테 스터디 16일차 TIL + 프로그래머스/1/86491. 최소직사각형

문제 설명명함 지갑을 만드는 회사에서 지갑의 크기를 정하려고 합니다. 다양한 모양과 크기의 명함들을 모두 수납할 수 있으면서, 작아서 들고 다니기 편한 지갑을 만들어야 합니다. 이러한 요건을 만족하는 지갑을 만들기 위해 디자인팀은 모든 명함의 가로 길이와 세로 길이를 조사했습니다.아래 표는 4가지 명함의 가로 길이와 세로 길이를 나타냅니다.명함 번호가로 길이세로 길이16050230703603048040가장 긴 가로 길이와 세로 길이가 각각 80, 70이기 때문에 80(가로) x 70(세로) 크기의 지갑을 만들면 모든 명함들을 수납할 수 있습니다. 하지만 2번 명함을 가로로 눕혀 수납한다면 80(가로) x 50(세로) 크기의 지갑으로 모든 명함들을 수납할 수 있습니다. 이때의 지갑 크기는 4000(=80 ..

[Brute Force]99클럽 코테 스터디 15일차 TIL + 프로그래머스/1/42840. 모의고사

문제 설명수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다.1번 수포자가 찍는 방식: 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...2번 수포자가 찍는 방식: 2, 1, 2, 3, 2, 4, 2, 5, 2, 1, 2, 3, 2, 4, 2, 5, ...3번 수포자가 찍는 방식: 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, ...1번 문제부터 마지막 문제까지의 정답이 순서대로 들은 배열 answers가 주어졌을 때, 가장 많은 문제를 맞힌 사람이 누구인지 배열에 담아 return 하도록 solution 함수를 작성해주세요..

[BST*]99클럽 코테 스터디 14일차 TIL + 0101-symmetric-tree

101. Symmetric TreeEasyGiven the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center). Example 1:Input: root = [1,2,2,3,4,4,3]Output: trueExample 2:Input: root = [1,2,2,null,3,null,3]Output: false Constraints:The number of nodes in the tree is in the range [1, 1000].-100  Follow up: Could you solve it both recursively and iteratively?  # Definition fo..

[BST*]99클럽 코테 스터디 13일차 TIL + 0783-search-in-a-binary-search-tree

783. Search in a Binary Search TreeEasyYou are given the root of a binary search tree (BST) and an integer val.Find the node in the BST that the node's value equals val and return the subtree rooted with that node. If such a node does not exist, return null. Example 1:Input: root = [4,2,7,1,3], val = 2Output: [2,1,3]Example 2:Input: root = [4,2,7,1,3], val = 5Output: [] Constraints:The number of..

[sort]99클럽 코테 스터디 12일차 TIL + 프로그래머스/1/12917. 문자열 내림차순으로 배치하기

문제 설명문자열 s에 나타나는 문자를 큰것부터 작은 순으로 정렬해 새로운 문자열을 리턴하는 함수, solution을 완성해주세요.s는 영문 대소문자로만 구성되어 있으며, 대문자는 소문자보다 작은 것으로 간주합니다.제한 사항str은 길이 1 이상인 문자열입니다.입출력 예sreturn"Zbcdefg""gfedcbZ"  def solution(s): result = sorted(s, reverse=True) answer = ''.join(result) return answer1. 어제와 비교- sort 와 sorted 의 차이를 명확히 이해하게 됨=> 덕분에 sort는 list가 아니기 때문에 안쓰는거 아닌가 생각하게 됨 - list로 return 된것을 문자열로 바꾸는것=> 곧바로 join을..