There is a collection of input strings and a collection of query strings. For each query string, determine how many times it occurs in the list of input strings. Return an array of the results.
Example
queries = [a', 'b', c'd']
strings = [a', b, c'd']
return => [1, 0, 1]
func matchingStrings(strings: [String], queries: [String]) -> [Int] {
// Hashmap - Dictionary // Arr - size/order
//var dics = [String : Int]()
var arr = [Int](0..<queries.count)
for i in 0..<queries.count {
arr[i] = 0
for j in strings {
if queries[i] == j {
arr[i] += 1
}
}
}
return arr
}
'Computer Science > Algorithm with Code' 카테고리의 다른 글
Leet Code (1492. Amazon Spring '23 HF) (0) | 2024.05.13 |
---|---|
Hacker Rank_5/54 tests (Easy, Lonely Integer) (0) | 2024.05.09 |
Hacker Rank_3/54 tests (Easy, Time Conversion) (0) | 2024.05.08 |
Hacker Rank_2/54 tests (Easy, Min-Max Sum) (0) | 2024.05.07 |
Hacker Rank_1/54 tests (Easy, Plus Minus) (0) | 2024.05.07 |