본문 바로가기

Java70

[Java] Annotation Annotation이란? 사전적 의미로는 주석이라는 뜻이다. 자바에서 Annotation은 코드 사이에 주석처럼 쓰이며 특별한 의미, 기능을 수행하도록 하는 기술이다. 즉, 프로그램에게 추가적인 정보를 제공해 주는 메타데이터(meta data)라고 볼 수 있다.(meta data : 데이터를 위한 데이터) 다음은 어노테이션의 용도를 나타낸 것이다. 1. 컴파일러에게 코드 작성 문법 에러를 체크하도록 정보를 제공한다. 2. 소프트웨어 개발 툴이 빌드나 배치 시 코드를 자동으로 생성할 수 있도록 정보를 제공한다. 3. 실행 시(런타임 시)특정 기능을 실행하도록 정보를 제공한다. 기본적으로 어노테이션을 사용하는 순서는 다음과 같다. 1. 어노테이션을 정의 2. 클래스에 어노테이션을 배치 3. 코드가 실행되는 .. 2023. 8. 15.
[Java] 프로그래머스 [Level-3] 네트워크 public class Solution { // 네트워크 static boolean[] visited = {}; public static void dfs(int i, int[][] computers) { visited[i] = true; for(int j = 0; j < computers[i].length; j++) { if(!visited[j] && computers[i][j] == 1) { dfs(j, computers); } } } public static int solution(int n, int[][] computers) { int answer = 0; visited = new boolean[n]; for(int i = 0; i < n; i++) { if(!visited[i]) { answer+.. 2023. 1. 1.
[Java] 프로그래머스 [Level-3] 단어 변환 public class Solution { // 단어 변환 static boolean[] visited = {}; static int gDepth = 0; public static boolean strCompare(String str1, String str2) { // str1과 str2의 길이가 같다는 조건 하에 int strLength = str1.length(); int cnt = 0; for(int i = 0; i < strLength; i++) { if(str1.charAt(i) != str2.charAt(i)) { cnt++; } } if(cnt == 1) { // 변형 조건에서 1글자만 바꿀 수 있는데 1글자만 다를 경우 return true; } else { return false; } }.. 2022. 12. 31.
[Java] 프로그래머스 [Level-2] 디펜스 게임 import java.util.PriorityQueue; public class Solution { // 디펜스 게임 public static int solution(int n, int k, int[] enemy) { int answer = enemy.length; // 모든 라운드 클리어 가능할 경우의 리턴 값 PriorityQueue pq = new PriorityQueue(); // 무적권을 사용해 해치울 적의 수를 남기기 위한 우선순위 큐 // 디펜스 게임 시작 for(int i = 0; i < enemy.length; i++) { // 4, 2, 4, 5, 3, 3, 1 pq.offer(enemy[i]); // 4 // 2, 4 // 2, 4, 4 // 2, 4, 4, 5 // 3, 4, 4, .. 2022. 12. 27.
[Java] 백준 [11048] 이동하기 public class Solution { // 이동하기 - DP 11048번 static int n = 3; static int m = 4; static int[][] arr = {{1, 2, 3, 4}, {0, 0, 0, 5}, {9, 8, 7, 6}}; static int[] dy = {1, 1, 0}; static int[] dx = {0, 1, 1}; static int[][] dp = new int[n][m]; public static void dfs(int a, int b) { for(int i = 0; i n - 1 || nx > m - 1) { continue; } // dp 갱신 .. 2022. 12. 26.
[Java] 백준 [2178] 미로 탐색 import java.util.LinkedList; import java.util.Queue; public class Solution { // 미로 탐색 - BFS 2178번 // 최단 거리 탐색 BFS static int r = 4; static int c = 6; static int[][] arr = {{1, 0, 1, 1, 1, 1}, {1, 0, 1, 0, 1, 0}, {1, 0, 1, 0, 1, 1}, {1, 1, 1, 0, 1, 1}}; static boolean[][] visit = {}; static int[] dx = {0, 0, -1, 1}; static int[] dy = {-1, 1, 0, 0}; public static void bfs(int n, int m) { Queue q =.. 2022. 12. 24.
[Java] 백준 [1541] 잃어버린 괄호 public class Solution { // 잃어버린 괄호 - Greedy 1541번 public static int solution(String str) { String[] strArr1 = str.split("-"); // 문자 "-" 기준으로 split int totalSum = 0; int tempSum = 0; // strArr1 = {"55", "50+40", "20", "30+40"} for (int i = 0; i < strArr1.length; i++) { tempSum = 0; String[] strArr2 = strArr1[i].split("\\+"); // 특수문자 "+" 기준으로 split (특수문자의 경우 \\특수문자 or [특수문자]) for (int j = 0; j < s.. 2022. 12. 18.
[Java] 백준 [7570] 줄 세우기 import java.util.Arrays; public class Solution { // 줄 세우기 - DP 7570번 // 제일 앞 또는 제일 뒤로만 이동 가능 // 연속된 가장 긴 증가하는 부분 수열 이용 static int n = 7; static int[] arr = {3, 7, 5, 2, 6, 1, 4}; static int[] dp = {1, 1, 1, 1, 1, 1, 1}; public static void setLine() { int clisCnt = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { if (arr[i] == arr[j] + 1) { dp[i] = Math.max(dp[i], dp[j] + 1); } } } .. 2022. 12. 17.
[Java] 백준 [2631] 줄 세우기 import java.util.Arrays; public class Solution { // 줄 세우기 - DP 2631번 // 이동 위치 제한 없음 // 가장 긴 증가하는 부분 수열(LIS) 이용 static int n = 7; static int[] arr = {3, 7, 5, 2, 6, 1, 4}; static int[] dp = {1, 1, 1, 1, 1, 1, 1}; public static void setLine() { int lisCnt = 0; for (int i = 0; i arr[j] && dp[i] 2022. 12. 17.