inblog logo
|
silver
    알고리즘문제풀기

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

    silver's avatar
    silver
    Dec 06, 2025
    [알고리즘문제풀기] 암호 해독
    Contents
    문제내가 작성한 정답다른 사람들의 정답

    문제

    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/120892

    내가 작성한 정답

    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

    RSS·Powered by Inblog