본문 바로가기

프로그래머스

프로그래머스 - 모의고사 실패한 코드class Solution { public int[] solution(int[] answers) { // int[] answers = {1,3,2,4,2}; int[] cnt = new int[3]; int[] answer = {}; int length = answers.length; int[][] arr = new int[3][length]; int std; int[] pattern1 = {1, 2, 3, 4, 5}; int[] pattern2 = {1, 3, 4, 5, 2}; int[] pattern3 = {3, 1, 2, 4, 5}; /** * 수포자 3명 배열 초기화 */ for (int i = 0; i < arr.length; i++) { if (i == 0) { for (int j ..
프로그래머스 - 짝수와 홀수 class Solution { public String solution(int num) { String answer = ""; answer = num % 2 == 0 ? "Even" : "Odd"; return answer; } }
프로그래머스 - 수박수박수박수박수박수? class Solution { public String solution(int n) { String answer = ""; int cnt = 1; while (cnt
프로그래머스 서울에서 김서방 찾기 class Solution { public String solution(String[] seoul) { String answer = ""; String str; int idx = -1; for (int i = 0; i List로 변경import java.util.Arrays; import java.util.List; class Solution { public String solution(String[] seoul) { Str..
프로그래머스 - 두 정수 사이의 합 class Solution { public long solution(int a, int b) { long answer = 0; int tmp; if (a > b) { tmp = a; a = b; b = tmp; } while (a
프로그래머스 - 완주하지 못한 선수 첫 코드 - 효율성 문제(시간복잡도 [O(n*n)])class Solution { public String solution(String[] participant, String[] completion) { String answer = ""; String str; int cntPart; int cntComp; for (int i = 0; i < participant.length; i++) { str = participant[i]; cntPart = 0; cntComp = 0; for (int j = 0; j < participant.length; j++) { if (str.equals(participant[j])) { cntPart++; } } for (int j = 0; j < completion.leng..