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

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

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; } }

➜ 코딩 테스트

프로그래머스 - 배열 만들기 5

import java.util.ArrayList; import java.util.List; class Solution { public int[] solution(String[] intStrs, int k, int s, int l) { List answer = new ArrayList(); for(int i = 0; i k){ answer.add(value); } } int[] result = new int[answer.size()]; for(int i = 0; i < answer.size(); i++){ result[i] = answer..

➜ 코딩 테스트/백준

백준 - (25556)포스택

1. 길이가 N인 순열과 4개의 비어 있는 스택이 있다. 2. 순열의 원소들을 앞에서부터 순서대로 네 개의 스택 중 하나에 삽입한다. 3. 순열의 모든 원소를 스택에 삽입했다면, 원하는 스택에서 수를 꺼내는 것을 반복하여 네 개의 스택에서 모든 수를 꺼낸다. 4. 꺼낸 수들을 꺼낸 순서대로 오른쪽에서 왼쪽으로 나열한다 순열을 1, 2, 3, ..., N으로 만들 수 있는지 여부를 판별해야 한다. 예제 입력 1 10 4 3 6 7 8 9 10 2 1 5 입력받은 숫자의 순서는 4, 3, 6, 7, 8, 9, 10, 2, 1, 5 이다 스택에 숫자를 삽입하는 규칙은 해당 숫자가 스택의 최상단 숫자보다 클 경우에만 가능하다. (numbers.get(i) > stacks.get(i).peek()) 숫자는 스택에..

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

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

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...

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

프로그래머스 - 9로 나눈 나머지

class Solution { public int solution(String number) { int answer = 0; for(int i = 0; i < number.length(); i++){ answer += Integer.parseInt(String.valueOf(number.charAt(i))); } return answer % 9; } }

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

프로그래머스 - 주사위 게임 3

import java.util.Arrays; class Solution { public int solution(int a, int b, int c, int d) { int[] dice = {a, b, c, d}; Arrays.sort(dice); // 모두 같은 숫자인 경우 if (dice[0] == dice[1] && dice[1] == dice[2] && dice[2] == dice[3]) { return 1111 * dice[0]; } // 세 개가 같은 숫자인 경우 else if ((dice[0] == dice[1] && dice[1] == dice[2]) || (dice[1] == dice[2] && dice[2] == dice[3])) { int sameValue = dice[1]; int d..

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

프로그래머스 - 간단한 논리 연산

class Solution { public boolean solution(boolean x1, boolean x2, boolean x3, boolean x4) { return (x1 || x2) && (x3 || x4); } }

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

프로그래머스 - 특정한 문자를 대문자로 바꾸기

class Solution { public String solution(String my_string, String alp) { String answer = ""; answer = my_string.replaceAll(alp , alp.toUpperCase()); return answer; } }

강맹석
'➜ 코딩 테스트' 카테고리의 글 목록 (30 Page)