본문 바로가기

Java/프로그래머스

(232)
[JAVA] 프로그래머스 - 두 정수 사이의 합 https://school.programmers.co.kr/learn/courses/30/lessons/12912 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr     정답  class Solution { public long solution(int a, int b) { long answer = 0; int min = Math.min(a,b); int max = Math.max(a,b); for(int i=min; i
[JAVA] 프로그래머스 - 나머지가 1이 되는 수 찾기 https://school.programmers.co.kr/learn/courses/30/lessons/87389 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr    정답  class Solution { public int solution(int n) { int answer = 0; for(int i=1; i
[JAVA] 프로그래머스 - 달리기 경주 https://school.programmers.co.kr/learn/courses/30/lessons/178871 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr       시도 1)  import java.util.Arrays;class Solution { public String[] solution(String[] players, String[] callings) { for(int i=0; i     정답 - HashMap에 plyers의 이름을 key로 인덱스를 value로 설정하여 배열을 순회하지 않고 시간복잡도 O(1..
[JAVA] 프로그래머스 - x만큼 간격이 있는 n개의 숫자 https://school.programmers.co.kr/learn/courses/30/lessons/12954 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr   시도 1) class Solution { public long[] solution(int x, int n) { long[] answer = new long[n]; int idx =0; for(int i=0; i    정답   class Solution { public long[] solution(int x, int n) { ..
[JAVA] 프로그래머스 - 추억 점수 https://school.programmers.co.kr/learn/courses/30/lessons/176963 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr       정답  import java.util.*;class Solution { public int[] solution(String[] name, int[] yearning, String[][] photo) { int[] answer = new int[photo.length]; int len = name.length; // key: 이름, ..
[JAVA] 프로그래머스 - 하샤드 수 https://school.programmers.co.kr/learn/courses/30/lessons/12947 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr     정답  class Solution { public boolean solution(int x) { boolean answer = true; int sum = 0; //각 자릿수 합 String s = String.valueOf(x); for(int i=0; i
[JAVA] 프로그래머스 - 평균 구하기 https://school.programmers.co.kr/learn/courses/30/lessons/12944 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr    정답  class Solution { public double solution(int[] arr) { double answer = 0; double sum = 0; int len = arr.length; for(int n : arr) { sum +=n; } ..
[JAVA] 프로그래머스 - 정수 제곱근 판별 https://school.programmers.co.kr/learn/courses/30/lessons/12934 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr    정답  class Solution { public long solution(long n) { long answer = 0; if(Math.pow((int)Math.sqrt(n),2)==n) { answer = (long)Math.pow(Math.sqrt(n)+1,2); } else ..