알고리즘/프로그래머스 1단계42 [프로그래머스] 콜라츠 추측 프로그래머스 1단계 콜라츠 추측 https://programmers.co.kr/learn/challenges 문제 설명 풀이 class Solution { public int solution(double num) { int answer = 0; if(num == 1) { return 0; } while(num != 1) { if(answer == 500) { return -1; } if(num % 2 == 0) { num /= 2; answer++; } else { num = num * 3 + 1; answer++; } System.out.print(num+" "); } return answer; } } 2022. 4. 23. [프로그래머스] 짝수와 홀수 프로그래머스 1단계 짝수와 홀수 https://programmers.co.kr/learn/challenges 문제 설명 제한 조건 - num은 int 범위의 정수입니다. - 0은 짝수입니다. 풀이 class Solution { public String solution(int num) { String answer; if(num%2==0) answer = "Even"; else answer = "Odd"; return answer; } } 2022. 4. 23. [프로그래머스] x만큼 간격이 있는 n개의 숫자 프로그래머스 1단계 x만큼 간격이 있는 n개의 숫자 https://programmers.co.kr/learn/challenges 문제 설명 풀이 class Solution { public long[] solution(long x, int n) { long[] answer; answer = new long[n]; for(int i=0; i 2022. 4. 23. [프로그래머스] 평균 구하기 프로그래머스 1단계 평균 구하기 https://programmers.co.kr/learn/challenges 문제 설명 풀이 class Solution { public double solution(int[] arr) { double answer = 0; for(int i = 0; i 2022. 4. 23. 이전 1 ··· 5 6 7 8 9 10 11 다음