코딩 문제 풀이52 [프로그래머스] Lv3 문제풀이8(feat. JAVA) 가장 긴 팬린드롬 class Solution { public int palindrome(int right, int left, String s) { while(right = 0 && s.charAt(right) == s.charAt(left)) { right++; left--; } return right - left - 1; } public int solution(String s) { int answer = 0; for(int i = 0; i < s.length(); i++) { answer = Math.max(answer, palindrome(i+1, i-1, s)); answer = Math.max(answer, palindrome(i+1, i, s)); } re.. 2023. 10. 24. [프로그래머스] Lv3 문제풀이7(feat. JAVA) 디스크 컨트롤 import java.util.*; import java.util.stream.IntStream; class Solution { class Job { int start; int cost; Job(int start, int cost) { this.start = start; this.cost = cost; } } public int solution(int[][] jobs) { int answer = 0; PriorityQueue heap = new PriorityQueue((o1, o2) -> { if(o1.start != o2.start) return o1.start - o2.start; else return o1.cost - o2.cost; }); IntStream.range(0, jobs.. 2023. 10. 13. [프로그래머스] Lv3 문제풀이6(feat. JAVA) 가장 먼 노드 import java.util.*; import java.util.stream.IntStream; class Solution { public int solution(int n, int[][] edge) { int answer = 0; ArrayList[] list = new ArrayList[n+1]; for(int[] e : edge) { int x = e[0]; int y = e[1]; if(list[x] == null) list[x] = new ArrayList(); list[x].add(y); if(list[y] == null) list[y] = new ArrayList(); list[y].add(x); } int[] dist = new int[n+1]; Arrays.fill(dis.. 2023. 10. 11. [프로그래머스] Lv3 문제풀이5(feat. JAVA) 불량 사용자 import java.util.*; class Solution { public int cnt = 0; public Set lst = new HashSet(); public void permutation(String[] user_id,String[] banned_id, int depth, int n, int r) { if (depth == r) { boolean wrong = false; String[] slist = new String[r]; for(int i = 0; i < r; i++) { if(banned_id[i].length() != user_id[i].length()){ wrong = true; break; } for(int j = 0; j < banned_id[i].length(.. 2023. 10. 10. [프로그래머스] Lv3 문제풀이4(feat. JAVA) 기지국 설치 import java.util.*; class Solution { public int solution(int n, int[] stations, int w) { int answer = 0; int end = 0; ArrayList area = new ArrayList(); for(int i = 0; i end) { area.add(start - end); } end = stations[i] + w; } if(n - end > 0) { area.add(n - end); } int scope = w * 2 + 1; for(int a : area) { answer += a /.. 2023. 10. 10. [백준] 자바 문제 풀이 5373 : 플래티넘5 BOJ 5373 : 큐빙 import java.io.*; import java.util.*; public class Main { static void rotate(char d, char[][] cube) { char[][] copy = new char[3][3]; for (int x = 0; x < 3; x++) for (int y = 0; y < 3; y++) { if (d == '+') copy[x][y] = cube[2-y][x]; else copy[x][y] = cube[y][2-x]; } for (int x = 0; x < 3; x++) for (int y = 0; y < 3; y++) cube[x][y] = copy[x][y]; } public static void main(String[] a.. 2023. 10. 9. [백준] 자바 문제 풀이 17143 : 골드1 BOJ 17143 : 낚시왕 import java.io.*; import java.util.*; public class Main { static class Shark { int s; int d; int z; Shark(int s, int d, int z) { this.s = s; this.d = d; this.z = z; } } public static void main(String[] args) throws Exception { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new Out.. 2023. 10. 8. [백준] 자바 문제 풀이 2493 : 골드5 BOJ 2493 : 탑 import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int n = Integer.parseInt(br.readLine()); StringTokenizer str = new StringTokenizer(br.. 2023. 10. 8. [백준] 자바 문제 풀이 5430 : 골드5 BOJ 5430 : AC import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); StringTokenizer st; int test_case = Integer.parseInt(br.readLine()); for(int i = 0; i < test_case; i++) { boolean rever.. 2023. 10. 8. [백준] 자바 문제 풀이 1351 : 골드5 BOJ 1351 : 무한 수열 import java.math.BigInteger; import java.util.*; import java.io.*; public class Main { static HashMap hm = new HashMap(); public static long dp(long n, long p, long q) { if(hm.containsKey(n)) return hm.get(n); hm.put(n, dp((long)Math.floor((double) n/p), p, q) + dp((long)Math.floor((double) n/q), p, q)); return hm.get(n); } public static void main(String[] args) throws Exception.. 2023. 10. 8. [백준] 자바 문제 풀이 13975 : 골드4 BOJ 13975 : 파일합치기3 import java.util.PriorityQueue; import java.io.*; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws Exception { BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int test_case = Integer.parseInt(br.readLine()); PriorityQueue pq; .. 2023. 10. 8. [백준] 자바 문제 풀이 10026 : 골드5 BOJ 10026 : 적록색약 import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; public class Main { static int n; static char[][] color; static char[][] abnor; static int[][] delta = { { -1, 0 }, { 1, 0 }, { 0, 1 }, { 0, -1 } }; static int cnt = 0; public static class Point{ int x; int y; char c; public Point(int x, .. 2023. 10. 6. 이전 1 2 3 4 5 다음 728x90 반응형