
문제 https://www.acmicpc.net/problem/7576 7576번: 토마토 첫 줄에는 상자의 크기를 나타내는 두 정수 M,N이 주어진다. M은 상자의 가로 칸의 수, N은 상자의 세로 칸의 수를 나타낸다. 단, 2 ≤ M,N ≤ 1,000 이다. 둘째 줄부터는 하나의 상자에 저장된 토마토 www.acmicpc.net 풀이 코드 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class Main { stati..

문제 https://www.acmicpc.net/problem/2178 2178번: 미로 탐색 첫째 줄에 두 정수 N, M(2 ≤ N, M ≤ 100)이 주어진다. 다음 N개의 줄에는 M개의 정수로 미로가 주어진다. 각각의 수들은 붙어서 입력으로 주어진다. www.acmicpc.net 풀이 코드 import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { static int[] dx = {0, 1, 0, -1}; static int[] dy = {1, 0, -1, 0}; private static class Point { int x; int y; public Point(int x, int ..

문제 https://www.acmicpc.net/problem/1926 1926번: 그림 어떤 큰 도화지에 그림이 그려져 있을 때, 그 그림의 개수와, 그 그림 중 넓이가 가장 넓은 것의 넓이를 출력하여라. 단, 그림이라는 것은 1로 연결된 것을 한 그림이라고 정의하자. 가로나 세로 www.acmicpc.net 풀이 코드 import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { static int[] dx = {0, 1, 0, -1}; static int[] dy = {1, 0, -1, 0}; static int max; private static class Point { int x; ..

문제 https://leetcode.com/problems/max-area-of-island/description/ Max Area of Island - LeetCode Can you solve this real interview question? Max Area of Island - You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are su leetcode.com 풀이 코드 class Solution { static int..

문제 https://leetcode.com/problems/keys-and-rooms/description/ Keys and Rooms - LeetCode Can you solve this real interview question? Keys and Rooms - There are n rooms labeled from 0 to n - 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key. Whe leetcode.com 풀이 코드 class Solution { /** * 0번째 room을 방문하..

문제 https://leetcode.com/problems/create-binary-tree-from-descriptions/description/ LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이 코드 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNo..

문제 https://leetcode.com/problems/symmetric-tree/description/ LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이 코드 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode ri..

문제 https://leetcode.com/problems/two-sum-iv-input-is-a-bst/description/ LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이 코드 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * ..

문제 https://leetcode.com/problems/count-good-nodes-in-binary-tree/description/ LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이 코드 DFS로 Tree를 순회한다. 각 Node의 값이 순회 경로 상에 있는 Node들의 최댓값보다 크면 최댓값을 변경하고 answer를 1 증가한다. Tree를 모두 ..

문제 https://leetcode.com/problems/find-elements-in-a-contaminated-binary-tree/description/ LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 풀이 코드 /** * Definition for a binary tree node. * public class TreeNode { * int val; *..