프로그래머스/Lv.1

프로그래머스/Lv.1

Lv.1 자연수 뒤집어 배열로 만들기

https://programmers.co.kr/learn/courses/30/lessons/12932 코딩테스트 연습 - 자연수 뒤집어 배열로 만들기 자연수 n을 뒤집어 각 자리 숫자를 원소로 가지는 배열 형태로 리턴해주세요. 예를들어 n이 12345이면 [5,4,3,2,1]을 리턴합니다. 제한 조건 n은 10,000,000,000이하인 자연수입니다. 입출력 예 n return 12345 programmers.co.kr 기본틀 class Solution { public int[] solution(long n) { int[] answer = {}; return answer; } } 첫번째 시도 import java.util.*; class Solution { public int[] solution(long..

프로그래머스/Lv.1

Lv.1 정수 내림차순으로 배치하기

https://programmers.co.kr/learn/courses/30/lessons/12933 코딩테스트 연습 - 정수 내림차순으로 배치하기 함수 solution은 정수 n을 매개변수로 입력받습니다. n의 각 자릿수를 큰것부터 작은 순으로 정렬한 새로운 정수를 리턴해주세요. 예를들어 n이 118372면 873211을 리턴하면 됩니다. 제한 조건 n은 1이 programmers.co.kr 기본틀 class Solution { public long solution(long n) { long answer = 0; return answer; } } 첫번째시도 import java.util.Arrays; import java.util.Collections; class Solution { public lon..

프로그래머스/Lv.1

Lv.1 정수 제곱근 판별

https://programmers.co.kr/learn/courses/30/lessons/12934 코딩테스트 연습 - 정수 제곱근 판별 임의의 양의 정수 n에 대해, n이 어떤 양의 정수 x의 제곱인지 아닌지 판단하려 합니다. n이 양의 정수 x의 제곱이라면 x+1의 제곱을 리턴하고, n이 양의 정수 x의 제곱이 아니라면 -1을 리턴하는 함 programmers.co.kr 기본틀 class Solution { public long solution(long n) { long answer = 0; return answer; } } 첫번째 시도 class Solution { public double solution(long n) { double x = Math.sqrt(n); double a = x - (..

프로그래머스/Lv.1

Lv.1 제일 작은 수 제거하기

https://programmers.co.kr/learn/courses/30/lessons/12935 코딩테스트 연습 - 제일 작은 수 제거하기 정수를 저장한 배열, arr 에서 가장 작은 수를 제거한 배열을 리턴하는 함수, solution을 완성해주세요. 단, 리턴하려는 배열이 빈 배열인 경우엔 배열에 -1을 채워 리턴하세요. 예를들어 arr이 [4,3,2,1 programmers.co.kr 기본틀 class Solution { public int[] solution(int[] arr) { int[] answer = {}; return answer; } } 첫번째 시도 class Solution { public int[] solution(int[] arr) { if(arr.length == 1){ in..

프로그래머스/Lv.1

Lv.1 최대공약수와 최소공배수

https://programmers.co.kr/learn/courses/30/lessons/12940 코딩테스트 연습 - 최대공약수와 최소공배수 두 수를 입력받아 두 수의 최대공약수와 최소공배수를 반환하는 함수, solution을 완성해 보세요. 배열의 맨 앞에 최대공약수, 그다음 최소공배수를 넣어 반환하면 됩니다. 예를 들어 두 수 3, 12의 programmers.co.kr 기본틀 class Solution { public int[] solution(int n, int m) { int[] answer = {}; return answer; } } 첫번째 시도 class Solution { public int[] solution(int n, int m) { int gcd = 0, lcm = 0; int ..

프로그래머스/Lv.1

Lv.1 콜라츠 추측

https://programmers.co.kr/learn/courses/30/lessons/12943 코딩테스트 연습 - 콜라츠 추측 1937년 Collatz란 사람에 의해 제기된 이 추측은, 주어진 수가 1이 될때까지 다음 작업을 반복하면, 모든 수를 1로 만들 수 있다는 추측입니다. 작업은 다음과 같습니다. 1-1. 입력된 수가 짝수라면 2 programmers.co.kr 기본틀 class Solution { public int solution(int num) { int answer = 0; return answer; } } 첫번째 시도 class Solution { public int solution(int num) { int answer = 0; while(num != 1){ if(answer =..

프로그래머스/Lv.1

Lv.1 평균 구하기

https://programmers.co.kr/learn/courses/30/lessons/12944 코딩테스트 연습 - 평균 구하기 정수를 담고 있는 배열 arr의 평균값을 return하는 함수, solution을 완성해보세요. 제한사항 arr은 길이 1 이상, 100 이하인 배열입니다. arr의 원소는 -10,000 이상 10,000 이하인 정수입니다. 입출력 예 arr programmers.co.kr 기본틀 class Solution { public double solution(int[] arr) { double answer = 0; return answer; } } 첫번째 시도 class Solution { public double solution(int[] arr) { double answer ..

프로그래머스/Lv.1

Lv.1 하샤드 수

https://programmers.co.kr/learn/courses/30/lessons/12947 코딩테스트 연습 - 하샤드 수 양의 정수 x가 하샤드 수이려면 x의 자릿수의 합으로 x가 나누어져야 합니다. 예를 들어 18의 자릿수 합은 1+8=9이고, 18은 9로 나누어 떨어지므로 18은 하샤드 수입니다. 자연수 x를 입력받아 x가 하 programmers.co.kr 기본틀 class Solution { public boolean solution(int x) { boolean answer = true; return answer; } } 첫번째 시도 class Solution { public boolean solution(int x) { boolean answer = true; int sum = 0;..

프로그래머스/Lv.1

Lv.1 핸드폰 번호 가리기

https://programmers.co.kr/learn/courses/30/lessons/12948 코딩테스트 연습 - 핸드폰 번호 가리기 프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다. 전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자 programmers.co.kr 기본틀 class Solution { public String solution(String phone_number) { String answer = ""; return answer; } } 첫번째 시도 class Solution { public String solution(String phone_number) { String answer ..

프로그래머스/Lv.1

Lv.1 행렬의 덧셈

https://programmers.co.kr/learn/courses/30/lessons/12950 코딩테스트 연습 - 행렬의 덧셈 행렬의 덧셈은 행과 열의 크기가 같은 두 행렬의 같은 행, 같은 열의 값을 서로 더한 결과가 됩니다. 2개의 행렬 arr1과 arr2를 입력받아, 행렬 덧셈의 결과를 반환하는 함수, solution을 완성해주세요 programmers.co.kr 기본틀 class Solution { public int[][] solution(int[][] arr1, int[][] arr2) { int[][] answer = {}; return answer; } } 첫번째 시도 class Solution { public int[][] solution(int[][] arr1, int[][] a..

코딩하는토끼
'프로그래머스/Lv.1' 카테고리의 글 목록 (4 Page)