전체 글 240

[DP]99클럽 코테 스터디 40일차 TIL + 0121-best-time-to-buy-and-sell-stock

121. Best Time to Buy and Sell StockEasyYou are given an array prices where prices[i] is the price of a given stock on the ith day.You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock.Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0. Example 1:Input: pric..

[DP]99클럽 코테 스터디 39일차 TIL + 1236-n-th-tribonacci-number

1236. N-th Tribonacci NumberEasyThe Tribonacci sequence Tn is defined as follows: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.Given n, return the value of Tn. Example 1:Input: n = 4Output: 4Explanation:T_3 = 0 + 1 + 1 = 2T_4 = 1 + 1 + 2 = 4Example 2:Input: n = 25Output: 1389537 Constraints:0 The answer is guaranteed to fit within a 32-bit integer, ie. answer .  class Solution:..

[DP]99클럽 코테 스터디 38일차 TIL + 0747-min-cost-climbing-stairs

747. Min Cost Climbing StairsEasyYou are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps.You can either start from the step with index 0, or the step with index 1.Return the minimum cost to reach the top of the floor. Example 1:Input: cost = [10,15,20]Output: 15Explanation: You will start at index 1.- ..

[Greedy]99클럽 코테 스터디 37일차 TIL + 0455-assign-cookies

455. Assign CookiesEasyAssume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie.Each child i has a greed factor g[i], which is the minimum size of a cookie that the child will be content with; and each cookie j has a size s[j]. If s[j] >= g[i], we can assign the cookie j to the child i, and the child i will be content. Your ..

[Greedy]99클럽 코테 스터디 36일차 TIL + 0409-longest-palindrome

409. Longest PalindromeEasyGiven a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters.Letters are case sensitive, for example, "Aa" is not considered a palindrome.Example 1:Input: s = "abccccdd"Output: 7Explanation: One longest palindrome that can be built is "dccaccd", whose length is 7.Example 2:Input: s =..

[BruteForce]99클럽 코테 스터디 35일차 TIL + 백준/Bronze/9094. 수학적 호기심

[Bronze III] 수학적 호기심 - 9094문제 링크성능 요약메모리: 32140 KB, 시간: 4588 ms -> 3797ms분류브루트포스 알고리즘, 수학제출 일자2024년 8월 27일 19:00:11문제 설명두 정수 n과 m이 주어졌을 때, 0 2+b2+m)/(ab)가 정수인 쌍의 개수를 구하는 프로그램을 작성하시오.입력첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있으며, n과 m이 주어진다. 두 수는 0보다 크고, 100보다 작거나 같다.출력각 테스트 케이스마다 문제의 조건을 만족하는 (a, b)쌍의 개수를 출력한다.  if __name__ == "__main__": case_number = int(input()) case = [] for..

[BruteForce]99클럽 코테 스터디 34일차 TIL + 백준/Bronze/1145. 적어도 대부분의 배수

[Bronze I] 적어도 대부분의 배수 - 1145문제 링크성능 요약메모리: 33240 KB, 시간: 32 ms분류브루트포스 알고리즘제출 일자2024년 8월 26일 22:52:31문제 설명다섯 개의 자연수가 있다. 이 수의 적어도 대부분의 배수는 위의 수 중 적어도 세 개로 나누어 지는 가장 작은 자연수이다.서로 다른 다섯 개의 자연수가 주어질 때, 적어도 대부분의 배수를 출력하는 프로그램을 작성하시오.입력첫째 줄에 다섯 개의 자연수가 주어진다. 100보다 작거나 같은 자연수이고, 서로 다른 수이다.출력첫째 줄에 적어도 대부분의 배수를 출력한다.  from itertools import combinationsfrom math import gcdif __name__ == "__main__": inp..

[DFS/BFS]99클럽 코테 스터디 33일차 TIL + 백준/Silver/2583. 영역 구하기

[Silver I] 영역 구하기 - 2583문제 링크성능 요약메모리: 31120 KB, 시간: 64 ms분류너비 우선 탐색, 깊이 우선 탐색, 그래프 이론, 그래프 탐색제출 일자2024년 8월 25일 22:13:17문제 설명눈금의 간격이 1인 M×N(M,N≤100)크기의 모눈종이가 있다. 이 모눈종이 위에 눈금에 맞추어 K개의 직사각형을 그릴 때, 이들 K개의 직사각형의 내부를 제외한 나머지 부분이 몇 개의 분리된 영역으로 나누어진다.예를 들어 M=5, N=7 인 모눈종이 위에 과 같이 직사각형 3개를 그렸다면, 그 나머지 영역은 와 같이 3개의 분리된 영역으로 나누어지게 된다.와 같이 분리된 세 영역의 넓이는 각각 1, 7, 13이 된다.M, N과 K 그리고 K개의 직사각형의 좌표가 주어질 때, K개의..

[DFS/BFS]99클럽 코테 스터디 32일차 TIL + 백준/Silver/양 한마리... 양 두마리...

[Silver II] 양 한마리... 양 두마리... - 11123문제 링크성능 요약메모리: 31120 KB, 시간: 264 ms분류너비 우선 탐색, 깊이 우선 탐색, 그래프 이론, 그래프 탐색제출 일자2024년 8월 24일 18:18:09문제 설명얼마전에 나는 불면증에 시달렸지... 천장이 뚫어져라 뜬 눈으로 밤을 지새우곤 했었지. 그러던 어느 날 내 친구 광민이에게 나의 불면증에 대해 말했더니 이렇게 말하더군. "양이라도 세봐!" 정말 도움이 안되는 친구라고 생각했었지. 그런데 막상 또 다시 잠을 청해보려고 침대에 눕고 보니 양을 세고 있더군... 그런데 양을 세다보니 이걸로 프로그램을 하나 짜볼 수 있겠단 생각이 들더군 후후후... 그렇게 나는 침대에서 일어나 컴퓨터 앞으로 향했지.양을 # 으로 나..

[DFS/BFS]99클럽 코테 스터디 31일차 TIL + 1653-number-of-good-leaf-nodes-pairs

1653. Number of Good Leaf Nodes PairsMediumYou are given the root of a binary tree and an integer distance. A pair of two different leaf nodes of a binary tree is said to be good if the length of the shortest path between them is less than or equal to distance.Return the number of good leaf node pairs in the tree. Example 1:Input: root = [1,2,3,null,4], distance = 3Output: 1Explanation: The leaf..