본문 바로가기

JAVA92

[프로그래머스/자바] [1차] 다트 게임 https://school.programmers.co.kr/learn/courses/30/lessons/17682 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public int solution(String dartResult) { int answer = 0; dartResult = dartResult.replaceAll("10",":"); int[] result = new int[3]; int num = dartResult.charAt(0)-48; int count = 0; for(int i=1;i=48 && ch 2024. 2. 2.
[프로그래머스/자바] 콜라 문제 https://school.programmers.co.kr/learn/courses/30/lessons/132267 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public int solution(int a, int b, int n) { int answer = 0; int left = n; while(left>=a){ answer += (left/a)*b; left = (left%a)+(left/a)*b; } return answer; } } 2024. 1. 29.
[프로그래머스/자바] import java.util.*; class Solution { public int solution(int n) { List list = new ArrayList(); list.add(2); if(n==2){ return 1; }else{ for(int i=3;iMath.sqrt(i)){ break; } 그러나 없이 실행하니 실행 시간도 오래 걸리고 시간초과가 나오는 예제도 있었다. 그러고나서 생각해보니 지난번에 풀었던 문제에서도 어차피 약수를 구할거 i의 제곱근까지만 계산을 하면되는구나 싶었다. 그래서 해당 코드를 추가해서 만약 i의 제곱근이하까지 나눠봤는데 안되면 이건 소수이다. 라고 하였다. 소수는 매번 2부터 나누는것이 아니라 list를 하나 만들어서 소수라고 계산되면 list에 추가하고, 그 .. 2024. 1. 28.
[프로그래머스/자바] 기사단원의 무기 https://school.programmers.co.kr/learn/courses/30/lessons/136798 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public int solution(int number, int limit, int power) { int answer = 0; for(int i=1;ilimit){ answer+=power; }else{ answer+=count; } } return answer; } } 처음 풀이는 이러하였다. 그러나 이렇게 제출을 하니 시간 초과가 나왔다. 그래서 생각한것이 1.. 2024. 1. 27.
[프로그래머스/자바] 소수 만들기 https://school.programmers.co.kr/learn/courses/30/lessons/12977 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr class Solution { public int solution(int[] nums) { int answer = 0; int length = nums.length; for(int i=0;i 2024. 1. 26.
[프로그래머스/자바] 과일 장수 https://school.programmers.co.kr/learn/courses/30/lessons/135808 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import java.util.Arrays; class Solution { public int solution(int k, int m, int[] score) { int answer = 0; int length = score.length; Arrays.sort(score); for(int i=length-m;i>=0;i-=m){ answer+=score[i]*m; } return answer; .. 2024. 1. 25.