➜ 코딩 테스트/백준

백준 - (1158)요세푸스 문제

이 문제는 Linkedlist를 활용해서 풀었다 이 문제는 K값의 인덱스 값에 맞는 리스트를 삭제하는 문제이다 package S4_Baekjoon; import java.util.LinkedList; import java.util.Scanner; public class Baekjoon1158 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); // 사용자로부터 N과 K를 입력받음 int N = sc.nextInt(); int K = sc.nextInt(); // 1부터 N까지의 수를 가진 LinkedList 생성 LinkedList list = new LinkedList(); for(int i = 1; i

➜ 코딩 테스트/백준

백준 - (2830)행성 X3

첫 골드 3 문제이다 좀 두려움이 앞섰지만 그래도 풀어보려고 노력해보겠다.. 문제는 어렵지 않다 그냥 XOR 연산 처리한걸 다 합하면 된다 하지만 그냥 풀게 되면 시간 초과가 난다 package G3_Baekjoon; import java.util.Scanner; public class Baekjoon2830 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] X3 = new int[N]; int answer = 0; for (int i = 0; i < N; i++) { X3[i] = sc.nextInt(); } for (int i = 0; i < X3.length..

➜ 코딩 테스트/백준

백준 - (10807)개수 세기

해시 테이블로 풀어야 되는 과제라 해시로 풀었다. package B5_Baekjoon; import java.util.HashMap; import java.util.Scanner; public class Baekjoon10807 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int N = sc.nextInt(); HashMap hashMap = new HashMap(); for(int i = 0; i < N; i++){ int number = sc.nextInt(); hashMap.put(number, hashMap.getOrDefault(number, 0) +1); } int v = sc.nextInt(); ..

➜ 코딩 테스트/백준

백준 - (9012)괄호

이번 문제는 stack을 활용하는 문제였으나 내가 풀 때는 stack을 쓰지 않고 풀었다. 괄호를 배열로 저장한다음 왼쪽 괄호와 오른쪽 괄호가 나올때 count를 올리거나 내렸다 그래서 만약 오른쪽 괄호가 한번 더 나오는 상황이 나오면 그것도 NO로 출력이 되게 했다. 오른쪽 괄호가 왼쪽 괄호보다 많아지는 상황에 대한 처리를 고민하느라 조금 어려웠다. package S4_Baekjoon; import java.util.Scanner; public class Baekjoon9012 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int T = sc.nextInt(); String[] VPS = new String[..

➜ 코딩 테스트/프로그래머스

프로그래머스 - 숫자 문자열과 영단어

String 값에 문자와 숫자가 섞여있는데 구별하는 문제이다 나는 숫자값은 answer에 따로 추가를 시켜주고 문자값들은 other 에 계속 넣어주고 문자를 완성시키면 other 값을 초기화시키고 숫자로 넣어주는 코드를 작성했다. package Programmers; public class ProgrammingBasic { public static void main(String[] args) { solution("one4seveneight"); } public static int solution(String s) { String answer = ""; String other = ""; for(int i = 0; i < s.length(); i++){ if(Character.isDigit(s.charAt(..

➜ 코딩 테스트/프로그래머스

프로그래머스 - 짝수는 싫어요

import java.util.ArrayList; class Solution { public static ArrayList solution(int n) { ArrayList answer = new ArrayList(); for(int i = 1; i

➜ Java

자료구조 힙(Heap)이란?

오늘은 힙(heap)에 대해서 알아볼 생각이다. 힙은 데이터에서 가장 큰(또는 가장 작은) 항목에 빠르게 접근하도록 설계된 트리 기반의 자료 구조이다. 데이터 정렬 , 우선순위 큐 등 다양한 알고리즘에서 활용된다. 힙(heap)이란? 힙은 '완전 이진 트리(complete binary tree)'의 한 종류로, 힙에 저장된 각 노드의 키(key)는 자식 노드의 키와 비교하여 특정 순서를 유지한다. 힙에는 두가지 유형이 있다. 최대 힙(Max Heap): 부모 노드의 키가 자식 노드의 키보다 항상 크거나 같다. 따라서 힙의 루트(root)는 항상 가장 큰 키를 가진 노드이다. 최소 힙(Min Heap): 부모 노드의 키가 자식 노드의 키보다 항상 작거나 같다. 이 경우, 루트는 항상 가장 작은 키를 가진 ..

➜ 코딩 테스트/프로그래머스

프로그래머스 - 의상

package Programmers; import java.util.Arrays; import java.util.HashMap; public class ProgrammingBasic { public static void main(String[] args) { String[][] clothes = {{"yellow_hat", "headgear"}, {"blue_sunglasses", "eyewear"}, {"green_turban", "headgear"}}; solution(clothes); } public static int solution(String[][] clothes) { HashMap hashMap = new HashMap(); for(int i = 0; i < clothes.length; i+..

➜ 코딩 테스트/프로그래머스

프로그래머스 - 기능개발

큐를 공부하면서 풀게된 문제다 아직은 어려운것 같다.. package Programmers; import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; public class ProgrammingBasic { public static void main(String[] args) { int[] progresses = {95, 90, 99, 99, 80, 99}; int[] speeds = {1,1,1,1,1,1}; solution(progresses, speeds); } public static int[] solution(int[] progresses, int[] speeds) { Queue queue = new Link..

➜ 코딩 테스트/프로그래머스

프로그래머스 - 나누어 떨어지는 숫자 배열

import java.util.Arrays; class Solution { public int[] solution(int[] arr, int divisor) { int count = 0; for(int i = 0; i < arr.length; i++){ if(arr[i] % divisor == 0){ count++; } } if(count == 0){ return new int[] {-1}; } int[] answer = new int[count]; int index = 0; for(int i = 0; i < arr.length; i++){ if(arr[i] % divisor == 0){ answer[index++] = arr[i]; } } Arrays.sort(answer); return answer;..

강맹석
맹석의 IT노트 & 일상 기록