코딩/알고리즘

import java.util.*; class Solution { int[][] a_land; public int solution(int[][] land) { int answer = 0; boolean[][] isVisited = new boolean[land.length][land[0].length]; // 발견된 석유지역 list List finds = new ArrayList(); for (int i = 0; i 0 && !isVisited[i][j]) { Place place = process(i, j, land, isVisited, new Place(..
class Solution { public int solution(int n, int[][] results) { int answer = 0; boolean[][] graph = new boolean[n][n]; // graph 인접배열 형태 초기화 for (int[] result : results) { int win = result[0] - 1; int lose = result[1] - 1; graph[win][lose] = true; } int count = 0; for (int p = 0; p < n; p++) { // node별로 앞뒤로 이어진 edge체크 int lose = countBehind(p, graph, new boolean[n]) - 1; int win = countFront(p, gr..
import java.util.*; class Solution { List list = new ArrayList(); List keywords = List.of("A", "E", "I", "O", "U"); boolean isFind = false; int count = 0; public int solution(String word) { int answer = 0; getCombi("", 0, word); return count; } void getCombi(String output, int depth, String target) { // 탐색완료 이후 모든 재귀함수 미실행 if (isFind) { return; } if (!output.isEmpty()) { count++; } // 단어를 찾으면 is..
import java.util.*; class Solution { public int solution(int alp, int cop, int[][] problems) { int answer = 0; int al_max = Arrays.stream(problems) .map(problem -> problem[0]) .max(Comparator.naturalOrder()).orElseThrow(); int co_max = Arrays.stream(problems) .map(problem -> problem[1]) .max(Comparator.naturalOrder()).orElseThrow(); // 이미 모든 문제를 풀 수 있는 경우 0 반환 if (alp >= al_max && cop >= co_max)..
import java.util.*; import java.util.stream.*; class Solution { public int[] solution(int[] progresses, int[] speeds) { List answer = new ArrayList(); Queue queue = new LinkedList(); for (int num : progresses) { queue.offer(num); } int day = 0; int index = 0; while (queue.size() > 0) { // 진행 날짜 변수 day++; // 처리 개수 변수 int removed = 0; while (true) { // speeds index 초과 시 탈출 if (index >= speeds.leng..
import java.util.*; class Solution { public int[] solution(String[] gems) { int[] answer = new int[2]; // 보석 종류 정리 Set cleared_gems = new HashSet(Arrays.asList(gems)); Map picked = new HashMap(); int start = 0; int distance = Integer.MAX_VALUE; // 보석 탐색 for (int i = 0; i < gems.length; i++) { String endGem = gems[i]; picked.put(endGem, picked.getOrDefault(endGem, 0) + 1); // 포인터로 탐색된 보석 개수 2 이상일..
🔍 아이디어 ✅ 각 층별로 옮기기 위한 점화식을 재귀코드로 표현 import java.util.*; class Solution { List moved = new ArrayList(); public List solution(int n) { hanoi(n, 1, 2, 3); return moved; } void hanoi(int count, int start, int sub, int end) { if (count == 1) { moved.add(new int[] { start, end }); return; } hanoi(count - 1, start, end, sub); moved.add(new int[] { start, end }); hanoi(count - 1, sub, start, end); } } ✔..
🔍 아이디어 ✅ Car 클래스를 생성해 값을 관리했다. import java.util.*; class Solution { public int[] solution(int[] fees, String[] records) { int[] answer = {}; Map carMap = new HashMap(); for (int i = 0; i < records.length; i++) { String[] record = records[i].split(" "); String time = record[0]; String name = record[1]; String type = record[2]; // Key가 없으면 값을 생성해서 값을 항상 얻을 수 있도록 보장 if (!carMap.containsKey(name)) {..
thisisdj
'코딩/알고리즘' 카테고리의 글 목록 (8 Page)