목록분류 전체보기 (188)
forest_moon
문제 설명 머쓱이는 RPG게임을 하고 있습니다. 게임에는 up, down, left, right 방향키가 있으며 각 키를 누르면 위, 아래, 왼쪽, 오른쪽으로 한 칸씩 이동합니다. 예를 들어 [0,0]에서 up을 누른다면 캐릭터의 좌표는 [0, 1], down을 누른다면 [0, -1], left를 누른다면 [-1, 0], right를 누른다면 [1, 0]입니다. 머쓱이가 입력한 방향키의 배열 keyinput와 맵의 크기 board이 매개변수로 주어집니다. 캐릭터는 항상 [0,0]에서 시작할 때 키 입력이 모두 끝난 뒤에 캐릭터의 좌표 [x, y]를 return하도록 solution 함수를 완성해주세요. [0, 0]은 board의 정 중앙에 위치합니다. 예를 들어 board의 가로 크기가 9라면 캐릭터는 ..
입출력 예 설명 입출력 예 #1 좌표 [[1, 1], [2, 1], [2, 2], [1, 2]] 를 꼭짓점으로 갖는 직사각형의 가로, 세로 길이는 각각 1, 1이므로 직사각형의 넓이는 1 x 1 = 1입니다. 입출력 예 #2 좌표 [[-1, -1], [1, 1], [1, -1], [-1, 1]]를 꼭짓점으로 갖는 직사각형의 가로, 세로 길이는 각각 2, 2이므로 직사각형의 넓이는 2 x 2 = 4입니다. import java.util.*; class Solution { public int solution(int[][] dots) { int answer = 0; int x = 0; int y = 0; for(int i = 1 ; i < 4; i++){ int a = Math.abs(dots[i-1][0] ..
입출력 예 설명 입출력 예 #1 [1, 1, 2, 3, 4, 5] 에는 1이 2개 있습니다. 입출력 예 #2 [0, 2, 3, 4] 에는 1이 0개 있습니다. class Solution { public int solution(int[] array, int n) { int answer = 0; for(int i=0; i< array.length; i ++){ if(array[i] == n){ answer ++; } } return answer; } }
class Solution { public String[] solution(String my_str, int n) { String[] answer = {}; if (my_str.length() % n == 0) answer = new String[my_str.length() / n]; else answer = new String[my_str.length() / n + 1]; for (int i = 0; i < answer.length; i++) { answer[i] = (i * n + n
문제보러가기 입출력 예 설명 입출력 예 #1 [7, 77, 17]에는 7이 4개 있으므로 4를 return 합니다. 입출력 예 #2 [10, 29]에는 7이 없으므로 0을 return 합니다. class Solution { public int solution(int[] array) { int answer = 0; for(int i=0; i
문제보러가기 입출력 예 설명 입출력 예 #1 "Bcad"를 모두 소문자로 바꾸면 "bcad"이고 이를 알파벳 순으로 정렬하면 "abcd"입니다. 입출력 예 #2 "heLLo"를 모두 소문자로 바꾸면 "hello"이고 이를 알파벳 순으로 정렬하면 "ehllo"입니다. 입출력 예 #3 "Python"를 모두 소문자로 바꾸면 "python"이고 이를 알파벳 순으로 정렬하면 "hnopty"입니다. import java.util.*; class Solution { public String solution(String my_string) { String answer = ""; String [] arr = my_string.toLowerCase().split(""); Arrays.sort(arr); for(int i..
문제보러가기 입출력 예 설명 입출력 예 #1 "b"와 "c"가 같으므로 2를 return합니다. 입출력 예 #2 같은 원소가 없으므로 0을 return합니다. class Solution { public int solution(String[] s1, String[] s2) { int answer = 0; for(int i=0 ; i
문제보러가기 입출력 예 설명 입출력 예 #1 "abcabcadc"에서 하나만 등장하는 문자는 "d"입니다. 입출력 예 #2 "abdc"에서 모든 문자가 한 번씩 등장하므로 사전 순으로 정렬한 "abcd"를 return 합니다. 입출력 예 #3 "hello"에서 한 번씩 등장한 문자는 "heo"이고 이를 사전 순으로 정렬한 "eho"를 return 합니다. import java.util.*; class Solution { public String solution(String s) { String answer = ""; String[] arr = s.split(""); Arrays.sort(arr); for(int i = 0; i