본문 바로가기

CodingTest/Programmers81

[프로그래머스] Lv.0 가장 큰 수 찾기 class Solution { public int[] solution(int[] array) { int[] answer = new int[2]; for(int i=0; i 2022. 11. 28.
[프로그래머스] Lv.0 대문자와 소문자* class Solution { public String solution(String my_string) { String answer = ""; for(int i=0; i 2022. 11. 28.
[프로그래머스] Lv.0 가위바위보 class Solution { public String solution(String rsp) { String answer = ""; for(int i=0; i 2022. 11. 28.
[프로그래머스] Lv.0 세균 증식 class Solution { public int solution(int n, int t) { int answer = n; for(int i=1; i 2022. 11. 28.
[프로그래머스] Lv.0 직각삼각형 출력하기* public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i=0; i 2022. 11. 28.
[프로그래머스] Lv.0 개미군단 class Solution { public int solution(int hp) { int ans = 0; if(hp%5==0) ans += hp/5; else{ ans += hp/5; hp = hp%5; if(hp%3==0) ans += hp/3; else{ ans += hp/3; hp = hp%3; ans += hp; } } return ans; } } 공격력이 5,3,1로 고정이기 때문에 매개변수로 들어온 hp에서 5,3,1로 나눈 몫이 필요한 각각의 개미의 수가 될 것이고 1)적은 수의 개미를 원하기 때문에 큰 수인 5부터 나누고 2)남은 나머지를 3으로 나누고 3)또 남은 나머지는 1로 나눈 몫을 계속 더해주는 방식 으로 풀었다. 그런데 다음 수로 나누기 전에 0이 되도 더해지는건 0이기 때문에.. 2022. 11. 28.
Lv.0 문자열 정렬하기(1)** import java.util.Arrays; class Solution { public int[] solution(String my_string) { String []removeA = my_string.replaceAll("[^0-9]", "").split(""); int []answer = new int[removeA.length]; for(int i=0; i 2022. 11. 23.
Lv.0 숨어있는 숫자의 덧셈 class Solution { public int solution(String my_string) { int answer = 0; String removeSt = my_string.replaceAll("[^0-9]", ""); for(int i=0; i 2022. 11. 23.
Lv.0 중앙값 구하기 import java.util.Arrays; class Solution { public int solution(int[] array) { int answer = 0; Arrays.sort(array); answer = array[array.length/2]; return answer; } } 제한사항에 array길이는 홀수로 고정이므로 array를 오름차순 정렬하고 array.length/2하면 중앙에 있는 인덱스를 가르킨다. 2022. 11. 23.
728x90
반응형