목록전체 글 (597)
넘치게 채우기
https://leetcode.com/problems/number-of-islands/description/ LeetCode - Number of Islands 문제 유형 : dfs/bfs, 행렬 문제 난이도 : Medium 문제 Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assume all four edges of the grid ar..
https://leetcode.com/problems/island-perimeter/description/ LeetCode - Island Perimeter 문제 유형 : 행렬 문제 난이도 : Easy 문제 You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or mor..
https://leetcode.com/problems/smallest-string-starting-from-leaf/description/ Leetcode - Smallest String Starting From Leaf 문제 유형 : 이진트리, 재귀, dfs 문제 난이도 : Medium 문제 You are given the root of a binary tree where each node has a value in the range [0, 25] representing the letters 'a' to 'z'. Return the lexicographically smallest string that starts at a leaf of this tree and ends at the root. As a ..
https://leetcode.com/problems/add-one-row-to-tree/description/ LeetCode - Add One Row to Tree 문제 유형 : 이진트리, dfs, 재귀 문제 난이도 : Medium 문제 Given the root of a binary tree and two integers val and depth, add a row of nodes with value val at the given depth depth. Note that the root node is at depth 1. The adding rule is: Given the integer depth, for each not null tree node cur at the depth depth - 1,..
https://leetcode.com/problems/sum-root-to-leaf-numbers/description/ Leetcode - Sum Root to Leaf Numbers 문제 유형 : dfs, 이진트리 문제 난이도 : Medium 문제 You are given the root of a binary tree containing digits from 0 to 9 only. Each root-to-leaf path in the tree represents a number. For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123. Return the total sum of all root-to-leaf numbers. T..
https://leetcode.com/problems/sum-of-left-leaves/description/ Leetcode - Sum of Left Leaves 문제 유형 : 이진 트리, dfs, 재귀 문제 난이도 : Easy 문제 Given the root of a binary tree, return the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf that is the left child of another node. 이진 트리의 루트가 주어진다. 모든 왼쪽 잎 노드의 값의 합을 구하시오. 잎 노드란 자식 노드가 없는 노드를 말합니다. 풀이 말 그대로 이진트리를 순회하면서 왼쪽 리프노드의 합을 반..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/DLgl2/btsGBRuuDau/3VGkIZVHkY6vPASkSbr0z0/img.png)
https://leetcode.com/problems/maximal-rectangle/description/ Leetcode - Maximal Rectangle 문제 유형 : 히스토그램, 스택, 다이나믹 프로그래밍 문제 난이도 : Hard 문제 Given a rows x cols binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. rows x cols크기의 이진 행렬이 주어진다. 1로만 이루어진 가장 큰 직사각형을 찾아서 그 크기를 반환하시오. 풀이 풀이 1: 다이나믹 프로그래밍(동적계획법) 처음에는 각 자리별로 1로 이어진 왼쪽 끝과 위쪽 끝을 구한 뒤, 크기를 일..
https://leetcode.com/problems/remove-k-digits/description/ Leetcode - Remove K Digits 문제 유형 : 스택 문제 난이도 : Medium 문제 Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num. 양의정수를 표현하는 문자열 num이 주어집니다. num에서 k개의 정수를 제거한 가장 작은 수를 구하시오. 풀이 스택을 이용하여 풀 수 있다. 수를 하나씩 스택에 담는다. 만약에 이번에 넣을 수보다 큰 수들이 있다면, 그 수들은 기존 스택에서..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/oJMm2/btsGuJ5aGX2/n8KDjm0C44zidJRuzIS08k/img.png)
https://leetcode.com/problems/reveal-cards-in-increasing-order/description/ Leetcode - Reveal Cards In Increasing Order 문제 유형 : 스택, 큐 문제 난이도 : Medium 문제 You are given an integer array deck. There is a deck of cards where every card has a unique integer. The integer on the ith card is deck[i]. You can order the deck in any order you want. Initially, all the cards start face down (unrevealed) in o..
https://leetcode.com/problems/time-needed-to-buy-tickets/description/ LeetCode - Time Needed to Buy Tickets 문제 유형 : 큐 문제 난이도 : Easy 문제 There are n people in a line queuing to buy tickets, where the 0th person is at the front of the line and the (n - 1)th person is at the back of the line. You are given a 0-indexed integer array tickets of length n where the number of tickets that the ith person ..