본문 바로가기

Algorithm (PS)63

[프로그래머스 Level 1] 자연수 뒤집어 배열로 만들기 [Java] 문제 https://school.programmers.co.kr/learn/courses/30/lessons/12932 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 import java.util.*; class Solution { public int[] solution(long n) { String s = ""+n; int[] answer = new int[s.length()]; int idx=0; while(true){ if(n==0) break; //마지막 부터 자리수를 배열에 순서대로 넣는다. answer[idx] = (int)(n%10); .. 2023. 8. 15.
[프로그래머스 Level 1] x만큼 간격이 있는 n개의 숫자 [Java] 문제 https://school.programmers.co.kr/learn/courses/30/lessons/12954 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 class Solution { public long[] solution(long x, int n) { long[] answer = new long[n]; for(int i=0; i 2023. 8. 15.
[프로그래머스 Level 1] 짝수와 홀수 [Java] 문제 https://school.programmers.co.kr/learn/courses/30/lessons/12937 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 코드 class Solution { public String solution(int num) { String answer = check(num); return answer; } public String check(int num){ if(Math.abs(num%2)==1){ //홀수 return "Odd"; }else { //짝수 return "Even"; } } } 2023. 8. 15.
[프로그래머스 Level 1] 약수의 합 [Java] 문제 https://school.programmers.co.kr/learn/courses/30/lessons/12928 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 class Solution { public int solution(int n) { int answer = 0; answer = getAns(n); return answer; } //약수의 합 구하기 public int getAns(int n){ int sum=0; for(int i=1; i 2023. 8. 15.
[프로그래머스 Level 1] 자릿수 더하기 [Java] 문제 https://school.programmers.co.kr/learn/courses/30/lessons/12931 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 풀이 import java.util.*; public class Solution { public int solution(int n) { int answer = getAns(n); return answer; } //각 자릿수 합 구하기 public int getAns(int n){ int sum=0; while(true){ if(n==0) break; //현재 자리수 더하기 sum += n%1.. 2023. 8. 15.
[프로그래머스 Level 1] 평균 구하기 [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; for(int i=0; i 2023. 8. 15.