프로그래머스(자바)/LV.0(자바)

    암호 해독- substring(), toCharArray(), char->String에 대입가능, step

    나의 풀이 class Solution { public String solution(String cipher, int code) { String answer = ""; char[] chars = cipher.toCharArray(); for(int i=code-1; iString에 대입가능 ▶ String문자열을 char타입 배열로 바꿈 다른 사람의 풀이1 -String문자열을 그대로 이용함 (배열로 바꾸지 않음) class Solution { public String solution(String cipher, int code) { String answer = ""; for(int i=code-1; i value % code == code - 1) .mapToObj(c -> String.valueOf(ci..

    배열회전시키기★ rotate()함수이용, List get(), remove(), add()

    나의 풀이 import java.util.*; import java.util.stream.Collectors; import static java.util.Collections.*; class Solution { public int[] solution(int[] numbers, String direction) { List list= Arrays.stream(numbers).boxed().collect(Collectors.toList()); if (direction.equals("right")) { rotate(list, 1); } else { rotate(list, -1); } int[] answer = list.stream().mapToInt(i -> i).toArray(); return answer; ..

    인덱스바꾸기★ 문자열→문자열배열→List swap(), join()

    나의 풀이 class Solution { public String solution(String my_string, int num1, int num2) { String answer=""; String[] array_word=my_string.split(""); String tmp=array_word[num1]; array_word[num1]=array_word[num2]; array_word[num2]=tmp; for(String s: array_word){ answer+=s; } return answer; } } ▶ split()의 리턴타입은 String배열 임에 주의 한다. 다른 사람의 풀이 import java.util.Arrays; import java.util.Collections; import ..

    주사위의 개수 → 연산의 순서에 주의하자 (괄호의 중요성)

    나의 틀린 풀이 public class Solution { public int solution(int[] box, int n) { int answer = 0; answer=box[0]/n * box[1]/n * box[2]/n; return answer; } } ▶ 위와 같은 경우 몫* 몫 * 몫이 아니라 ▶ 몫*box[1]가 되는 불상사가 일어난다. 올바른 풀이 public class Solution { public int solution(int[] box, int n) { int answer = 0; answer=(box[0]/n) * (box[1]/n) * (box[2]/n); return answer; } } ▶ 괄호를 반드시 해줘서 올바른 연산을 하자