본문 바로가기

분류 전체보기351

[leetcode 84] Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3]. The largest rectangle is shown in the shaded area, which has area = 10 unit. 문제 풀이: 지난번에 풀었던 문제와 알고리즘이 동일하다. 또 못푼건 함정 ㅎㅎ.... eazymean.tistory.com/130 2020. 11. 8.
[leetcode 38] Count and Say The count-and-say sequence is a sequence of digit strings defined by the recursive formula: countAndSay(1) = "1" countAndSay(n) is the way you would "say" the digit string from countAndSay(n-1), which is then converted into a different digit string. To determine how you "say" a digit string, split it into the minimal number of groups so that each group is a contiguous section all of the same cha.. 2020. 11. 8.
[leetcode 73] Set Matrix Zeroes Given an m x n matrix. If an element is 0, set its entire row and column to 0. Do it in-place. Follow up: A straight forward solution using O(mn) space is probably a bad idea. A simple improvement uses O(m + n) space, but still not the best solution. Could you devise a constant space solution? Example 1: Input: matrix = [[1,1,1],[1,0,1],[1,1,1]] Output: [[1,0,1],[0,0,0],[1,0,1]] Example 2: Input.. 2020. 11. 7.
[백준 14891] 톱니바퀴 www.acmicpc.net/problem/14891 14891번: 톱니바퀴 총 8개의 톱니를 가지고 있는 톱니바퀴 4개가 아래 그림과 같이 일렬로 놓여져 있다. 또, 톱니는 N극 또는 S극 중 하나를 나타내고 있다. 톱니바퀴에는 번호가 매겨져 있는데, 가장 왼쪽 톱니바퀴 www.acmicpc.net 문제를 잘못이해해서 애먹었던 문제이다. 마주해있는 톱니의 N,S가 같으면 회전을 하지 않는게 요점이다. 그때 그때 톱니를 돌리는 것이 아니라 방향이 전부 나오면 한번에 톱니바퀴를 돌려줘야 한다. #include #include #define RIGHT 2 #define LEFT 6 using namespace std; int gear[4][8]; int dir[4]; void rotate(int cur, i.. 2020. 11. 7.