분류 전체보기 155

[JAVA] 프로그래머스 알고리즘 문제풀이 - Level 0 (95~100번 문제풀이)

95. 잘라서 배열로 저장하기 class Solution { public String[] solution(String my_str, int n) { int numlength = 0; if(my_str.length() % n == 0){ numlength = my_str.length()/n; }else { numlength = my_str.length()/n + 1; } String[] answer = new String[numlength]; for(int i=0; i= n){ answer[i] = my_str.substring(0, n); my_str = my_str.substring(n, my_str.length()); }else { answer[i] = my_str.substring(0, my_str..

[JAVA] 프로그래머스 알고리즘 문제풀이 - Level 0 (82~88번 문제풀이)

82. 편지 class Solution { public int solution(String message) { int answer = 0; answer = 2 * message.length(); return answer; } } 풀면서도 의심했다. 그냥 2만 곱해주면 됐다. 쉬어가기 문제인가 보다. 83. 가장 큰 수 찾기 import java.util.*; class Solution { public int[] solution(int[] array) { int[] answer = new int[2]; int max = array[0]; answer[0] = array[0]; answer[1] = 0; for(int i=1; i max){ max = array[i]; answer[0] = max; answ..

[JAVA] 프로그래머스 알고리즘 문제풀이 - Level 0 (69~74번 문제풀이)

69. 이진수 더하기 class Solution { public String solution(String bin1, String bin2) { String answer = ""; int rBin1 = ten(bin1); int rBin2 = ten(bin2); int sum = rBin1 + rBin2; answer = two(sum); return answer; } public int ten(String a){ int result = Integer.parseInt(a, 2); return result; } public String two(int a){ if(a == 0){ return "0"; } String result = ""; while(a > 0){ result = a%2 + result; a ..

[JAVA] 프로그래머스 알고리즘 문제풀이 - Level 0 (41~48번 문제풀이)

41. 공 던지기 class Solution { public int solution(int[] numbers, int k) { int answer = 1; for(int i=1; inumbers.length) answer -= numbers.length; } return answer; } } 던지는 사람은 1번째부터 시작하기 때문에 answer을 1로 초기화해 주었다. 42. 배열 회전시키기 class Solution { public int[] solution(int[] numbers, String direction) { int[] answer = new int[numbers.length]; if(direction.equals("right")){ for(int i=0; i

[JAVA] 프로그래머스 알고리즘 문제풀이 - Level 0 (33~40번 문제풀이)

33. 진료순서 정하기 class Solution { public int[] solution(int[] emergency) { int[] answer = new int[emergency.length]; for(int i=0; i 0){ answer = 1; }else { answer = 4; } } if(dot[0] 0){ answer = 2; }else { answer = 3; } } return answer; } } x좌표가 0보다 클 때, 작을때로 한번 나눴고 내부에서 y좌표가 0보다 클때, 작을 때의 조건문을 넣어서 값에 맞는 1, 2, 3, 4분면으로 반환해 주었다. 40. 2차원으로 만들기 class Solution { public int[][] solution(..

프로필사진

남건욱's 공부기록

반응형