Java69 [Java] 프로그래머스 [Level-2] [1차] 캐시 import java.util.LinkedList; public class Solution { // [1차] 캐시 // LRU(Least Recently Used) : 가장 오랫동안 참조되지 않은 페이지를 교체하는 방식 // 캐시가 가득 찼을 때, 가장 오랫동안 참조되지 않은 페이지를 찾아서 없애는 과정이 필요 public static int solution(int cacheSize, String[] cities) { int answer = 0; String city = ""; LinkedList cache = new LinkedList(); if (cacheSize == 0) { return cities.length * 5; } for (int i = 0; i < cities.length; i++) {.. 2022. 11. 28. [Java] 프로그래머스 [Level-3] 자물쇠와 열쇠 public class Solution { // 자물쇠와 열쇠 // key, lock 3이상 20이하 크기의 2차원 배열 // key는 회전과 이동이 가능 public static boolean openLock(int[][] checkArr, int point, int lockLength) { // point : 체크용 배열 checkArr에서 실제 lock의 시작 위치 // lockLength : lock의 길이 for (int i = 0; i < lockLength; i++) { for (int j = 0; j < lockLength; j++) { if (checkArr[point + i][point + j] != 1) return false; // 0 : 채워지지 않은 공간, 2 : 튀어나온 부분끼.. 2022. 11. 28. [Java] 프로그래머스 [TEST] Uncompress String import java.util.Stack; public class Solution { // 압축 문자열 풀기 public static String solution(String compressed) { String answer = ""; // 최종 문자열을 담을 변수 Stack charStack = new Stack(); // 영단어와 '(' 괄호를 담을 스택 Stack numStack = new Stack(); // 숫자를 담을 스택 String tempStr = ""; // 임시 문자열을 담을 변수 int tempNum = 0; // 임시 숫자를 담을 변수 String repeatStr = ""; // 반복 문자열을 담을 변수 StringBuilder sb = new StringBuilder(); //.. 2022. 11. 28. [Java] 프로그래머스 [TEST] ID Recommendation import java.util.HashMap; import java.util.HashSet; public class Solution { // 아이디 추천 // S(3 ~ 6 길이 영 소문자) + N(0 ~ 6 길이 숫자) 조합의 아이디를 추천한다. public static String solution(String[] registered_list, String new_id) { // 등록된 아이디 배열, 신규 아이디 String answer = ""; int registeredStrEndIdx = 0; // 등록된 아이디의 S + N 조합에서 S의 마지막 인덱스를 담을 변수 int newStrEndIdx = 0; // 신규 아이디의 S + N 조합에서 S의 마지막 인덱스를 담을 변수 String tempS.. 2022. 11. 28. [Java] 프로그래머스 [TEST] Anagram import java.util.*; public class Solution { // 애너그램 관계 public static int solution(int[] arr) { int answer = 0; String tempStr = ""; HashSet hs = new HashSet(); // HashSet 사용 //HashMap hm = new HashMap(); // HashMap 사용 for (int i = 0; i < arr.length; i++) { char[] charArr = Integer.toString(arr[i]).toCharArray(); Arrays.sort(charArr); // 오름차순 정렬 tempStr = new String(charArr); // 문자열 생성 if (!hs.co.. 2022. 11. 28. [Java] 프로그래머스 [Level-3] 등굣길 public class Solution { // 등굣길 static int[][] dp = {}; public static int solution(int m, int n, int[][] puddles) { int answer = 0; dp = new int [n][m]; // n행 m열 dp[0][0] = 1; // 집 for (int[] puddle : puddles) { dp[puddle[1] - 1][puddle[0] - 1] = -1; // 웅덩이 -1로 } for (int i = 0; i < n; i++) { // 행 for (int j = 0; j < m; j++) { // 열 if (dp[i][j] == -1) { // 웅덩이라면 dp[i][j] = 0; // 0으로 값 변경 후 contin.. 2022. 11. 28. 이전 1 ··· 4 5 6 7 8 9 10 ··· 12 다음