1단계

import java.util.Stack; class Solution { public int solution(int[][] board, int[] moves) { int answer = 0; Stack stack = new Stack(); stack.push(0); for (int i = 0; i < moves.length; i++) { int select = moves[i] - 1; for (int j = 0; j < board.length; j++) { if (board[j][select] != 0) { if (stack.peek() == board[j][select]) { stack.pop(); answer += 2; } else{ stack.push(board[j][select]); } board..
import java.util.Arrays; class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; Arrays.sort(participant); Arrays.sort(completion); for(int i=0; i 조건문을 통해 맨 뒤의 값을 return 한다.
import java.util.Arrays; /* 0부터 9까지의 숫자 중 일부가 들어있는 배열 numbers가 매개변수로 주어집니다. numbers에서 찾을 수 없는 0부터 9까지의 숫자를 모두 찾아 더한 수를 return 하도록 solution 함수를 완성해주세요. */ class Solution { public int solution(int[] numbers) { int answer = 0; Arrays.sort(numbers); int[]ar = new int [10]; for(int i = 0; i
원칙 하나를 깼다. 혼자 힘으로 풀어보려고 했지만 거리 구하는 부분이 해결이 되지 않아 소위 '삽질'을 많이 해본 것 같다. 1,2,3번은 풀이하기 쉬운 문제였다. 4번이 문제였는데, 왼쪽 손의 위치 오른쪽 손의 위치를 기억하여 거리를 구한 후 더 가까운 거리에 있는 손가락으로 2,5,8,0을 누르면 된다. 결국 답안을 보게 되었다. 키패드를 좌표로 두고 (0,0)(0,1)(0,3) 이렇게 좌표를 구해 왼쪽 손가락의 거리 (비교) 오른쪽 손가락의 거리 -> 거리가 짧은 거리의 손가락을 answer에 추가, 같다면 왼손잡이, 오른손 잡이에 따라 answer에 (R or L) 추가 class Solution { public String solution(int[]arr, String hand) { String..
class Solution { public String solution(String new_id) { String answer = ""; new_id = new_id.toLowerCase(); String[] str = new_id.split(""); String alphabet = "abcdefghijklnmopqrstuvwxyz.-_1234567890"; for (String s : str) { if (alphabet.contains(s)) { answer += s; } } String tmp = answer; answer = ""; tmp = tmp.replace("..", "."); while (tmp.contains("..")) { tmp = tmp.replace("..", "."); } if(..
class Solution { public int[] solution(int[] lottos, int[] win_nums) { int[] answer = new int [2]; int match = 0; for(int i = 0; i
알아가자
'1단계' 태그의 글 목록 (2 Page)