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 }
๋๊ธ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.