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