๊ธ€ ์ž‘์„ฑ์ž: ์ด์ง€์›๐ŸŒฉ๏ธ

16:26

์ •ํ™•์„ฑ์€ ํ†ต๊ณผํ–ˆ์ง€๋งŒ, ํšจ์œจ์„ฑ์—์„œ ์‹œ๊ฐ„ ์ดˆ๊ณผ๋กœ ์‹คํŒจํ–ˆ๋‹ค. ์นด์นด์˜ค ๋ธ”๋กœ๊ทธ์— ์žˆ๋Š” ํ’€์ด๋ฅผ ์ฝ๊ธด ํ–ˆ๋Š”๋ฐ, ์Œโ€ฆ.

๋ฌธ์ œ

https://programmers.co.kr/learn/courses/30/lessons/72412


๋‚ด๊ฐ€ ์ž‘์„ฑํ•œ ์ฝ”๋“œ

Swift

// ์ •ํ™•์„ฑ O, ํšจ์œจ์„ฑ X
import Foundation
func solution(_ info:[String], _ query:[String]) -> [Int] {
var table = [[String]]()
var result = [Int]()
for i in info {
let split = i.split(separator: " ").map { String($0) }
table.append(split)
}
for q in query {
let command = q.split(separator: " ").map { String($0) }
// ์–ธ์–ด ํ•„ํ„ฐ๋ง
var filtered = table
if command[0] != "-" {
filtered = filtered.filter {
return command[0] == $0[0]
}
}
// ์ง๊ตฐ ํ•„ํ„ฐ๋ง
if command[2] != "-" {
filtered = filtered .filter {
return command[2] == $0[1]
}
}
// ๊ฒฝ๋ ฅ ํ•„ํ„ฐ๋ง
if command[4] != "-" {
filtered = filtered.filter {
return command[4] == $0[2]
}
}
// ์†Œ์šธ ํ‘ธ๋“œ ํ•„ํ„ฐ๋ง
if command[6] != "-" {
filtered = filtered.filter {
return command[6] == $0[3]
}
}
// ์ ์ˆ˜ ํ•„ํ„ฐ๋ง
if command[7] != "-" {
filtered = filtered.filter {
return Int(command[7])! <= Int($0[4])!
}
}
result.append(filtered.count)
}
return result
}
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€

๋Œ“๊ธ€์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.