CodingTest 123

[프로그래머스 / Java] Lv.1 햄버거 만들기

Question https://school.programmers.co.kr/learn/courses/30/lessons/133502 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCodeimport java.util.*;class Solution { public int solution(int[] ingredient) { int answer = 0; Stack stack = new Stack(); for(int i : ingredient) { stack.push(i); if(stack.size() >= 4) { ..

[프로그래머스 / Java] Lv.2 올바른 괄호

Question https://school.programmers.co.kr/learn/courses/30/lessons/12909 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCodeimport java.util.*;class Solution { boolean solution(String s) { boolean answer = true; Stack stack = new Stack(); for (char item : s.toCharArray()) { if (item == '(') { stack.push..

[프로그래머스 / Java] Lv.1 푸드 파이트 대회

Question https://school.programmers.co.kr/learn/courses/30/lessons/134240 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCode💡방법 1class Solution { public String solution(int[] food) { String answer = "0"; for (int i = food.length - 1; i > 0; i--) { for (int j = 0; j String + int는 결과가 String타입이다. 💡방법 2class Solution { public Str..

[프로그래머스 / Java] Lv.1 문자열 내 p와 y의 개수

Question https://school.programmers.co.kr/learn/courses/30/lessons/12916 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCodeclass Solution { boolean solution(String s) { s = s.toLowerCase(); int count = 0; for (int i = 0; i toLowerCase() Java에서 문자열(String)의 모든 문자를 소문자로 변환할 때 사용하는 메서드원본 문자열은 변경되지 않고 새로운 소문자 문자열을 반환 (새로운 문자열 객체가 힙 메모리에 새로..

[프로그래머스 / Java] Lv.1 두 정수 사이의 합

Question https://school.programmers.co.kr/learn/courses/30/lessons/12912 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCode💡방법 1class Solution { public long solution(int a, int b) { return sumAtoB(Math.min(a, b), Math.max(b, a)); } private long sumAtoB(long a, long b) { return (b - a + 1) * (a + b) / 2; }}Math.max() 두 숫자 중 최대값 반환Mat..

[프로그래머스 / Java] Lv.0 삼각형의 완성조건 (1)

Question https://school.programmers.co.kr/learn/courses/30/lessons/120889 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCode💡방법 1import java.util.Arrays;class Solution { public int solution(int[] sides) { int answer = 0; Arrays.sort(sides); if(sides[2] 💡방법 2import java.util.Arrays;class Solution { public int solut..

[프로그래머스 / Java] Lv.1 자연수 뒤집어 배열로 만들기 (StringBuilder 정리하기...)

Question https://school.programmers.co.kr/learn/courses/30/lessons/12932 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCode💡방법 1class Solution { public int[] solution(long n) { String reversed = new StringBuilder(String.valueOf(n)).reverse().toString(); int[] answer = new int[reversed.length()]; for (int i = 0; i StringBuilderString.valu..

[프로그래머스 / Java] Lv.1 짝수와 홀수

Question https://school.programmers.co.kr/learn/courses/30/lessons/12937 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCode💡내 풀이class Solution { public String solution(int num) { String answer = ""; if(num % 2 == 0) { answer = "Even"; } else { answer = "Odd"; } return answer; }} ?..

[프로그래머스 / Java] Lv.1 자릿수 더하기

Question https://school.programmers.co.kr/learn/courses/30/lessons/12931 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.krCodeimport java.util.*;public class Solution { public int solution(int n) { int answer = 0; while(n > 0) { answer += n % 10; n = n / 10; } return answer; }}n % 10 : n의 마지막 자릿수를 구..