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

    [JAVA 문제 풀이] 275. [1차] 비밀지도

    프로그래머스 (17681)
    Stupefyee's avatar
    Stupefyee
    May 23, 2025
    [JAVA 문제 풀이] 275. [1차] 비밀지도
    Contents
    내가 작성한 코드다른 사람의 코드
    school.programmers.co.kr
    https://school.programmers.co.kr/learn/courses/30/lessons/17681
    notion image
    notion image
    notion image
     

    내가 작성한 코드

    class Solution { public String[] solution(int n, int[] arr1, int[] arr2) { String[] answer = new String[n]; for (int i = 0; i < n; i++) { String binary = Integer.toBinaryString(arr1[i] | arr2[i]); // 2진법 OR 연산 binary = String.format("%" + n + "s", binary).replace(" ", "0"); // 2진법으로 변환 후 n자리로 맞추기 answer[i] = binary.replace("0", " ").replace("1", "#"); } return answer; } }
     

    다른 사람의 코드

    class Solution { public String[] solution(int n, int[] arr1, int[] arr2) { String[] answer = new String[n]; String temp; for(int i = 0 ; i < n ; i++){ temp = String.format("%16s", Integer.toBinaryString(arr1[i] | arr2[i])); temp = temp.substring(temp.length() - n); temp = temp.replaceAll("1", "#"); temp = temp.replaceAll("0", " "); answer[i] = temp; } return answer; } }
    • 미리 16자리 2진수로 만들어두고 필요한만큼 자르기
     
    Share article
    Contents
    내가 작성한 코드다른 사람의 코드

    stupefyee

    RSS·Powered by Inblog