-
// 출처:프로그래머스, // https://school.programmers.co.kr/learn/courses/30/lessons/181906 //풀이 과정 * import java.util.*; class Solution { public int solution(String my_string, String is_prefix) { List<String> prefix = new ArrayList<>(); String[] split_string = my_string.split(""); for(String i: split_string){ int now_len = prefix.size(); if(now_len==0){ prefix.add(i); continue; } String last_word = prefix.get(now_len-1); String new_word = last_word+i; prefix.add(new_word); } for(String word:prefix){ if( word.equals(is_prefix) ){ System.out.print(my_string); return 1; } } System.out.print(prefix); return 0; } }
-
// 출처:프로그래머스, // https://school.programmers.co.kr/learn/courses/30/lessons/181911 // 풀이 과정 class Solution { public String solution(String[] my_strings, int[][] parts) { String answer = ""; int i = 0; for(String string_section: my_strings ){ String[] split_section = string_section.split(""); int s = parts[i][0]; int e = parts[i][1]; i++; for(int k = s; k<=e; k++){ answer+=split_section[k]; } } return answer; } }
-
// 출처:프로그래머스, // https://school.programmers.co.kr/learn/courses/30/lessons/181913 // 풀이과정 * class Solution { public String solution(String my_string, int[][] queries) { String answer = ""; String[] string_split = my_string.split(""); String after_str = ""; int start; for(int[] check_index:queries){ int s = check_index[0]; int e = check_index[1]; after_str =""; String now_str = ""; for(int i=e; i>=s; i--){ now_str = string_split[i]; after_str +=now_str; } start = s; for(String change_str:after_str.split("")){ string_split[start] = change_str; start++; } } for(String sum_alpha: string_split){ answer+=sum_alpha; } return answer; } }
-
//출처:프로그래머스, //https://school.programmers.co.kr/learn/courses/30/lessons/181918 // list 정의 import java.util.*; class Solution { public int[] solution(int[] arr) { List<Integer> result = new ArrayList<>(); int i = 0; while(i<arr.length){ if(result.size()==0){ result.add(arr[i]); i++; } else{ if( result.get(result.size()-1) <arr[i]){ result.add(arr[i]); i++; } else{ result.remove(result.size()-1); } } // System.out.println(result); } // System.out.print(result); int[] stk = new int[result.size()]; for(int k =0; k<result.size(); k++){ stk[k]=result.get(k); } return stk; } }
-
//출처:프로그래머스 //https://school.programmers.co.kr/learn/courses/30/lessons/181921 /* 범위의 숫자를 for문을 만든 후 해당 숫자를 string으로 변경 후 split 후 각 숫자에 대하여 0,5 진단 그리고 맞으면 append */ // 부족한 개념: 객체 타입 정의도 확인해보기,다이아몬드 연산자, 생성자 호출 import java.util.*; // *:라이브러리 내 모든 거 가져오기 class Solution { public int[] solution(int l, int r) { ArrayList<Integer> check = new ArrayList<>(); for(int i=l; i<=r; i++){ // 쪼개기 위해 한 정수 문자로 변환 String num = String.valueOf(i); // 변환한 문자를 한 문자씩 분리(5,0만 있는 지 확인 위해서) String[] num_split = num.split(""); //new HashSet<>(Arrays.asList(arr)); // set으로 바꾼 후 중복 제거 Set<String> num_set = new HashSet<>(Arrays.asList(num_split)); // 예시 조건 Set<String> case1 = new HashSet<>(Arrays.asList("5")); Set<String> case2 = new HashSet<>(Arrays.asList("0")); Set<String> case3 = new HashSet<>(Arrays.asList("0","5")); if(num_set.equals(case1) || num_set.equals(case2) || num_set.equals(case3) ){ check.add(i); } } // 자바 조건에 따라 리스트 배열로 바꾸기 int[] result = new int[check.size()]; for(int t = 0; t < check.size(); t++ ){ result[t] = check.get(t); } if(result.length == 0){ return new int[]{-1}; } else{ return result; } } }
-
//출처:프로그래머스, //https://school.programmers.co.kr/learn/courses/30/lessons/181923 class Solution { public int[] solution(int[] arr, int[][] queries) { int[] result = new int[queries.length]; int count = 0; for(int[] array_num:queries){ int s=array_num[0]; int e=array_num[1]; int k=array_num[2]; int start = k; int change = 0; for(int i=s; i<=e; i++){ if(arr[i]>k && start<arr[i] && change==0 ){ start = arr[i]; change = 1; } else if(arr[i]>k && start>arr[i] && change!=0 ){ start = arr[i]; } } if(start==k){ result[count]=-1; count++; } else{ result[count]=start; count++; } } return result; } }
-
//출처:프로그래머스, //https://school.programmers.co.kr/learn/courses/30/lessons/181924?language=java class Solution { public int[] solution(int[] arr, int[][] queries) { for(int[] change: queries){ int i = change[0]; int j = change[1]; int fir = arr[i]; int sec = arr[j]; arr[i] = sec; arr[j] = fir; } return arr; } }
-
// 출처:프로그래머스, // https://school.programmers.co.kr/learn/courses/30/lessons/181930 class Solution { public int solution(int a, int b, int c) { if(a==b && a!=c){ double result =(a+b+c)*(Math.pow(a,2)+Math.pow(b,2)+Math.pow(c,2)); return (int) result; } else if (a==c && a!=b){ double result =(a+b+c)*(Math.pow(a,2)+Math.pow(b,2)+Math.pow(c,2)); return (int) result; } else if (b==c && b!=a){ double result =(a+b+c)*(Math.pow(a,2)+Math.pow(b,2)+Math.pow(c,2)); return (int) result; } else if (b==c && a==c){ double result =(a+b+c)*(Math.pow(a,2)+Math.pow(b,2)+Math.pow(c,2))*(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)); return (int) result; } else{ return a+b+c; } } }
-
// 출처: 프로그래머스, // https://school.programmers.co.kr/learn/courses/30/lessons/181936 풀이 과정 class Solution { public int solution(int number, int n, int m) { if(number%n == 0 && number%m == 0 ){ return 1; } else{ return 0; } } }
-
""" 출처:프로그래머스, https://school.programmers.co.kr/learn/courses/30/lessons/389480 """ from collections import deque def solution(info, n, m): q=deque( [ [0,0] ] ) check=deque(info) visited = set([(0,0)]) result=[] while check: # 감당해야할 리스크 da,db=check.popleft() # 리스크를 감당했을 때의 위험도 담는 곳 new_q=deque([]) while q: a,b=q.popleft() if a>=n or b>=m: continue elif a<n and b>=m: new_q.append((a+da,b)) elif a>=n and b<m: new_q.append((a,b+db)) else: new_q.append((a+da,b)) new_q.append((a,b+db)) if len(new_q)==0: return -1 if len(check)==0: result=deque(set(new_q)) else: q=q+deque(set(new_q)) final=[] for last_a,last_b in result: if last_a < n and last_b <m: final.append(last_a) return -1 if len(final) == 0 else min(final)