[알고리즘문제풀기] 암호 해독

silver's avatar
Dec 06, 2025
[알고리즘문제풀기] 암호 해독

문제

내가 작성한 정답

class Solution { public String solution(String cipher, int code) { StringBuilder answer = new StringBuilder(); for(int i=code-1; i<cipher.length(); i+=code ){ answer.append(cipher.charAt(i)); } return answer.toString(); } }

다른 사람들의 정답

class Solution { public String solution(String cipher, int code) { String answer = ""; for (int i = code; i <= cipher.length(); i = i + code) { answer += cipher.substring(i - 1, i); } return answer; } } import java.util.stream.Collectors; import java.util.stream.IntStream; class Solution { public String solution(String cipher, int code) { return IntStream.range(0, cipher.length()) .filter(value -> value % code == code - 1) .mapToObj(c -> String.valueOf(cipher.charAt(c))) .collect(Collectors.joining()); } }
Share article

silver