알고리즘/프로그래머스 1단계42 [프로그래머스] 크레인 인형뽑기 게임 프로그래머스 1단계 크레인 인형뽑기 게임 https://programmers.co.kr/learn/challenges 문제 설명 풀이 import java.util.*; class Solution { public int solution(int[][] board, int[] moves) { int answer = 0; int depth = 0; ArrayList doll = new ArrayList(); for(int i=0; i 2022. 4. 24. [프로그래머스] 하샤드 수 프로그래머스 1단계 하샤드 수 https://programmers.co.kr/learn/challenges 문제 설명 풀이 class Solution { public boolean solution(int x) { boolean answer = false; int sum = 0; int xValue = x; while(xValue != 0) { sum += xValue % 10; xValue /= 10; } if (x % sum == 0) { answer = true; } return answer; } } 2022. 4. 24. [프로그래머스] 최대공약수와 최소공배수 프로그래머스 1단계 최대공약수와 최소공배수 https://programmers.co.kr/learn/challenges 문제 설명 풀이 /* 유클리드 호제법 : 두 수를 곱한 뒤 최대공약수로 나눈 값은 최소공배수이다. */ class Solution { public int[] solution(int n, int m) { int[] answer = new int[2]; int big; if(n > m) { big = n; } else { big = m; } while(true) { if(n%big == 0 && m%big == 0) { answer[0] = big; answer[1] = n*m/big; break; } else { big -= 1; } } return answer; } } 2022. 4. 24. [프로그래머스] K번째 수 프로그래머스 1단계 K번째 수 https://programmers.co.kr/learn/challenges 문제 설명 풀이 import java.util.Arrays; class Solution { public int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; int[] number = new int[array.length]; for(int i=0; i 2022. 4. 24. 이전 1 ··· 4 5 6 7 8 9 10 11 다음