题目为leetcode 383题, https://leetcode.com/problems/ransom-note
using map: 12ms, faster than 62.24%
```
func canConstruct(ransomNote string, magazine string) bool {
m := make(map[rune] int, 0)
for _, v := range magazine {
m[v]++
}
for _, v := range ransomNote {
m[v]--
if m[v] < 0 {
return false
}
}
return true
}
```
using array, 0ms faster than 100%
```
func canConstruct(ransomNote string, magazine string) bool {
m := make([] int, 26)
for _, v := range magazine {
m[v - 'a']++
}
for _, v := range ransomNote {
m[v - 'a']--
if m[v - 'a'] < 0 {
return false
}
}
return true
}
```
使用这两种数据结构结果差这么多原因是什么呢,有大神可以科普下吗
有疑问加站长微信联系(非本文作者)