mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-07 01:44:56 +08:00
add: leetcode 0383 solution
This commit is contained in:
18
leetcode/0383.Ransom-Note/383.Ransom Note.go
Normal file
18
leetcode/0383.Ransom-Note/383.Ransom Note.go
Normal file
@ -0,0 +1,18 @@
|
||||
package leetcode
|
||||
|
||||
func canConstruct(ransomNote string, magazine string) bool {
|
||||
if len(ransomNote) > len(magazine) {
|
||||
return false
|
||||
}
|
||||
var cnt [26]int
|
||||
for _, v := range magazine {
|
||||
cnt[v-'a']++
|
||||
}
|
||||
for _, v := range ransomNote {
|
||||
cnt[v-'a']--
|
||||
if cnt[v-'a'] < 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user