본문 바로가기

전체 글101

[프로그래머스] L2 소수 만들기 [프로그래머스] L2 소수 만들기 [풀이] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 class Solution { static int answer = 0; static boolean[] primeN= new boolean[3001]; static boolean[] chk = new boolean[3001]; public int solution(int[] nums) { solve(0,0,0,nums); return answer; } static void solve(int idx, int sum, int cnt, int[] nums){ for(int i=0; i 2020. 12. 15.
[프로그래머스] L2 영어 끝말잇기 [프로그래머스] L2 영어 끝말잇기 [풀이] 두 가지 조건에 유의하여 구현한다. 1. 앞 단어의 마지막 글자와 뒷 단어의 첫 글자가 같은지 여부(구현) 2. 이전에 나온 단어인지(HashSet 사용) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import java.util.*; class Solution { public int[] solution(int n, String[] words) { int[] answer = new int[] {0,0}; Set set = new HashSet(); set.add(words[0]); for(int i=1; i 2020. 12. 15.
[프로그래머스] L2 점프와 순간 이동 [프로그래머스] L2 점프와 순간 이동 [풀이] N이 10억이기 때문에 배열로 체크하는 경우 메모리초과가 나거나 DP를 사용하는 경우 시간초과가 발생한다. 따라서 주어진 N이 홀수인 경우 -1, 짝수인 경우 나누기 2를 해주어 최종적으로 1이 나오도록 만든다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import java.util.*; public class Solution { public int solution(int n) { int ans = 1; while(n>1){ if(n%2==1){ ans++; n -= 1; } n /= 2; } return ans; } } Colored by Color Scripter cs 2020. 12. 15.
[프로그래머스] L2 캐시 / 2018 카카오 블라인드 채용 [프로그래머스] L2 캐시 / 2018 카카오 블라인드 채용 [풀이] LRU 리스트를 만든다 1) 리스트에 도시 이름이 존재할 경우(cache hit) => 해당하는 도시 이름을 리스트에서 삭제 후 맨 앞에 다시 추가 2) 리스트에 도시 이름이 존재하지 않은 경우(cache miss) => 리스트에 추가 * 캐시 사이즈는 LRU 리스트를 조회할 때 break하는 것으로 해결! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 import java.util.*; class Solution { public int solution(int cacheSize, String[] cities) { int answer = 0; if(cach.. 2020. 12. 15.
[프로그래머스] L2 스킬트리 [프로그래머스] L2 스킬트리 [풀이] 주어진 스킬 순서에 한 글자라도 어긋나는 것이 생길 경우, 카운트를 하지 않는다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 class Solution { public int solution(String skill, String[] skill_trees) { int answer = 0; int end = skill.length(); for(int i=0; i 2020. 12. 15.
[프로그래머스] L2 괄호 변환 / 2020 카카오 블라인드 채용 [프로그래머스] L2 괄호 변환 / 2020 카카오 블라인드 채용 [풀이] 구현이 까다로워 여러번 실패를 했지만, 주어진 조건에 맞추어 자~~알 구현하는 것이 정답이었다... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 class Solution { public static String solution(String p) { String answer = ""; if(p.equals("")) return answer; // 1.빈문자열 else{ if(ch.. 2020. 12. 15.