➜ 코딩 테스트/프로그래머스

프로그래머스 - 나누어 떨어지는 숫자 배열

import java.util.Arrays; class Solution { public int[] solution(int[] arr, int divisor) { int count = 0; for(int i = 0; i < arr.length; i++){ if(arr[i] % divisor == 0){ count++; } } if(count == 0){ return new int[] {-1}; } int[] answer = new int[count]; int index = 0; for(int i = 0; i < arr.length; i++){ if(arr[i] % divisor == 0){ answer[index++] = arr[i]; } } Arrays.sort(answer); return answer;..

➜ 코딩 테스트/프로그래머스

프로그래머스 - qr code

class Solution { public String solution(int q, int r, String code) { String answer = ""; for(int i = r; i < code.length(); i += q){ answer += code.charAt(i); } return answer; } } 바로 전 편에서 배운 for문 커스텀하기 방법을 응용해서 쉽게 풀었다. 뿌듯하다 2023.07.12 - [➜ 코딩 테스트/프로그래머스] - 프로그래머스 - 세로 읽기 프로그래머스 - 세로 읽기 package Programmers; public class ProgrammingBasic { public static void main(String[] args) { String my_string ..

➜ 코딩 테스트/프로그래머스

프로그래머스 - 세로 읽기

package Programmers; public class ProgrammingBasic { public static void main(String[] args) { String my_string = "ihrhbakrfpndopljhygc"; solution(my_string, 4, 2); } public static String solution(String my_string, int m, int c) { String[][] str = new String[my_string.length()/m][m]; int start = 0; for(int i = 0; i < str.length; i++){ str[i] = my_string.substring(start, start + m).split(""); star..

➜ 코딩 테스트/프로그래머스

프로그래머스 - 문자열 뒤집기

class Solution { public String solution(String my_string, int s, int e) { StringBuilder sb = new StringBuilder(my_string); sb.replace(s, e + 1 , new StringBuilder(my_string.substring(s, e + 1)).reverse().toString()); return sb.toString(); } } 이제는 문자열 뒤집기 하면 공식같아보이는 존재이다..

➜ 코딩 테스트/프로그래머스

프로그래머스 - 접두사인지 확인하기

class Solution { public int solution(String my_string, String is_prefix) { String[] str = new String[my_string.length()]; int start = my_string.length(); int result = 0; for (int i = 0; i < my_string.length(); i++) { str[i] = my_string.substring(0,start); start--; } for (int i = 0; i < str.length; i++) { if (str[i].equals(is_prefix)) { result = 1; } } if(result != 1){ result = 0; } return result..

➜ 코딩 테스트/프로그래머스

프로그래머스 - 접미사인지 확인하기

class Solution { public int solution(String my_string, String is_suffix) { int start = 0; int result = 0; String[] suf = new String[my_string.length()]; for(int i = 0; i < my_string.length(); i++){ suf[i] = my_string.substring(start); start++; } for(int i = 0; i < suf.length; i++){ if(suf[i].equals(is_suffix)){ result = 1; } } if(result != 1){ result = 0; } return result; } } 내가 풀은 코드 class Solu..

➜ 코딩 테스트/프로그래머스

프로그래머스 - 접미사 배열

package Programmers; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class ProgrammingBasic { public static void main(String[] args) { String my_string = "banana"; solution(my_string); } public static List solution(String my_string) { List list = new ArrayList(); int start = 0; for(int i = 0; i < my_string.length(); i++){ list.add(my_string.substring(start..

➜ 코딩 테스트/프로그래머스

프로그래머스 - 부분 문자열 이어 붙여 문자열 만들기

package Programmers; public class ProgrammingBasic { public static void main(String[] args) { String[] my_strings = {"progressive", "hamburger", "hammer", "ahocorasick"}; int[][] parts = {{0,4}, {1, 2}, {3, 5}, {7,7}}; solution(my_strings, parts); } public static String solution(String[] my_strings, int[][] parts) { String answer = ""; for(int i = 0; i < parts.length; i++){ answer += my_strings[..

➜ 코딩 테스트/프로그래머스

프로그래머스 - 같은 숫자는 싫어

import java.util.*; public class Solution { public static Stack solution(int []arr) { Stack stack = new Stack(); stack.push(arr[0]); for(int i = 1; i < arr.length; i++){ if(stack.peek() != arr[i]){ stack.push(arr[i]); } } return stack; } }

➜ 코딩 테스트/프로그래머스

프로그래머스 - 문자열 여러 번 뒤집기

class Solution { public String solution(String my_string, int[][] queries) { String answer = ""; StringBuilder sb = new StringBuilder(my_string); for (int i = 0; i < queries.length; i++) { int start = queries[i][0]; int startcount = start; int end = queries[i][1]; int endcount = end; for (int j = 0; j < (endcount - startcount) / 2 + 1; j++) { char temp = sb.charAt(start); sb.setCharAt(start, sb...

강맹석
'➜ 코딩 테스트/프로그래머스' 카테고리의 글 목록 (28 Page)