본문 바로가기

Coding Test/프로그래머스

(138)
[프로그래머스/자바] 배열 원소의 길이 class Solution { public int[] solution(String[] strlist) { int[] answer = new int[strlist.length]; for(int i=0; i
[프로그래머스/자바] 개미 군단 class Solution { public int solution(int hp) { int answer = 0; while(hp>=5){ hp-=5; answer++; } while(hp>=3){ hp-=3; answer++; } while(hp>0){ hp--; answer++; } return answer; } } class Solution { public int solution(int hp) { return hp / 5 + (hp % 5 / 3) + (hp % 5 % 3); } }
[프로그래머스/자바] 자릿수 더하기 class Solution{ public int solution(int n) { int answer = 0; while (n > 0) { answer += n % 10; n /= 10; } return answer; } }
[프로그래머스/자바] 약수의 합('자바 입문' 강의 마지막 문제) class Solution { public int solution(int n) { int answer = 0; for(int i=1; i
[프로그래머스/자바] 삼각형의 완성조건(1) class Solution { public int solution(int[] sides) { int max = 0; int sum = 0; for(int i : sides){ if(maxmax) return 1; else return 2; } } import java.util.Arrays; class Solution { public int solution(int[] sides) { int answer = 0; Arrays.sort(sides); return sides[2] >= sides[0]+sides[1] ? 2 : 1; } } Arrays.sort 와 삼항 연산자를 이용한 풀이
[프로그래머스/자바] 문자열 뒤집기 class Solution { public String solution(String my_string) { String answer = ""; for(int i=my_string.length()-1; i>=0; i--){ answer += my_string.charAt(i); } return answer; } } class Solution { public String solution(String my_string) { StringBuilder sb = new StringBuilder(); sb.append(my_string); return sb.reverse().toString(); } } StringBuilder를 사용하여 푸는 방법 class Solution { public String solutio..
[프로그래머스/자바] 양꼬치 class Solution { public int solution(int n, int k) { int answer = n*12000+k*2000; if(n>=10){ answer -= 2000*(n/10); } return answer; } } class Solution { public int solution(int n, int k) { return n * 12000 + k * 2000 - (n / 10 * 2000); } }
[프로그래머스/자바] 배열의 평균 값 class Solution { public double solution(int[] numbers) { double answer = 0; for(int i=0; i