dfs
-
프로그래머스 - 카카오 프렌즈 컬러링북 [자바]Algorithms/- 프로그래머스 2022. 2. 14. 22:30
문제 링크 : 카카오 프렌즈 컬러링북 코딩테스트 연습 - 카카오프렌즈 컬러링북 6 4 [[1, 1, 1, 0], [1, 2, 2, 0], [1, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 3], [0, 0, 0, 3]] [4, 5] programmers.co.kr 정답 class Solution { private int[] x = {1, -1, 0, 0}; private int[] y = {0, 0, 1, -1}; private int temp = 0; public int[] solution(int m, int n, int[][] picture) { int numberOfArea = 0; int maxSizeOfOneArea = 0; boolean[][] v = new boolean[m..
-
LeetCode - Binary Tree Inorder Traversal [Java]Algorithms/- LeetCode 2022. 2. 7. 22:56
문제 링크 : Binary Tree Inorder Traversal Binary Tree Inorder Traversal - LeetCode 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 정답(Solution) Stack 풀이 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(in..
-
프로그래머스 - 단체사진 찍기 [자바] (feat. += , + 차이)Algorithms/- 프로그래머스 2022. 2. 6. 22:18
문제 링크 : 단체사진 찍기 코딩테스트 연습 - 단체사진 찍기 단체사진 찍기 가을을 맞아 카카오프렌즈는 단체로 소풍을 떠났다. 즐거운 시간을 보내고 마지막에 단체사진을 찍기 위해 카메라 앞에 일렬로 나란히 섰다. 그런데 각자가 원하는 배치가 모두 programmers.co.kr 정답 class Solution { private int answer = 0; private String[] arr = {"A", "C", "F", "J", "M", "N", "R", "T"}; public int solution(int n, String[] data) { boolean[] v = new boolean[arr.length]; dfs("", v, data); return answer; } private void df..
-
순서 트리 탐색 (너비 우선 탐색 : BFS, 깊이 우선 탐색 : DFS)컴퓨터공학/- 자료구조 2022. 2. 5. 11:56
순서 트리 순서 트리는 각 노드에 순서가 부여된 트리를 말한다. 예를 들어 위와 같은 2개의 트리가 있는 경우 무순서 트리에서는 B와 C의 순서가 부여되지 않았기 때문에 위 2개의 트리는 동일한 트리이다. 하지만 순서 트리에서는 B와 C에 순서가 부여되었기 때문에 위 2개의 트리는 다른 트리이다. 이진 트리 탐색 이진 트리는 순서 트리 중 노드의 자식 노드가 최대 2개인 경우를 말한다. 컴퓨터 과학에서 이진 트리를 이용해 값을 탐색하고 이것을 이진 트리 탐색이라고 한다. 다음은 이진 트리 탐색 방법 중 너비 우선 탐색과 깊이 우선 탐색에 대해 정리해본다. 너비 우선 탐색(Breadth-First Search, BFS) 너비 우선 탐색은 낮은 레벨(깊이)에서 시작해 왼쪽에서 오른쪽 방향으로 탐색하고 해당 ..
-
LeetCode - path sum [Java]Algorithms/- LeetCode 2022. 1. 30. 21:02
문제 링크 : path sum Path Sum - LeetCode 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 정답(Solution) /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, Tree..
-
프로그래머스 - 네트워크 [자바]Algorithms/- 프로그래머스 2022. 1. 30. 18:15
문제 링크 : 네트워크 코딩테스트 연습 - 네트워크 네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있 programmers.co.kr 정답(Solution) - 20220209 다시 풀이 class Solution { public int solution(int n, int[][] computers) { int answer = 0; boolean[] v = new boolean[n]; for(int i=0; i
-
프로그래머스 - 타겟 넘버 [자바]Algorithms/- 프로그래머스 2022. 1. 30. 17:51
문제 링크 : 타겟 넘버 코딩테스트 연습 - 타겟 넘버 n개의 음이 아닌 정수들이 있습니다. 이 정수들을 순서를 바꾸지 않고 적절히 더하거나 빼서 타겟 넘버를 만들려고 합니다. 예를 들어 [1, 1, 1, 1, 1]로 숫자 3을 만들려면 다음 다섯 방법을 쓸 수 programmers.co.kr 정답 1. 재귀 : dfs함수가 int를 리턴하는 풀이 class Solution { public int solution(int[] numbers, int target) { int answer = 0; answer = dfs(numbers, 0, 0, target); return answer; } private int dfs(int[] numbers, int nodeNum, int sum, int target){ ..