Skip to content

[Leeds] 비밀지도 #72

@Jung2un

Description

@Jung2un

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

import Foundation

func solution(_ n:Int, _ arr1:[Int], _ arr2:[Int]) -> [String] {
    var answer: [String] = []

    for i in 0..<n {
        var first = String(arr1[i], radix: 2)
        var second = String(arr2[i], radix: 2)

        if first.count < n {
            let max = n - first.count

            for _ in 0..<max {
                first = "0" + first
            }
        }

        if second.count < n {
            let max = n - second.count

            for _ in 0..<max {
                second = "0" + second
            }
        }

        var row = ""

        for j in 0..<n {
            if first[first.index(first.startIndex, offsetBy: j)] == "1" || second[second.index(second.startIndex, offsetBy: j)] == "1" {
                row += "#"
            } else {
                row += " "
            }
        }

        answer.append(row)
    }

    return answer
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions