add new solutions
This commit is contained in:
parent
ccb8b5673b
commit
58527849b2
6 changed files with 202 additions and 0 deletions
25
solutions/3/q383/solution.go
Normal file
25
solutions/3/q383/solution.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package q383
|
||||
|
||||
func canConstruct(ransomNote string, magazine string) bool {
|
||||
counts := make([]int, 'z'-'a'+1)
|
||||
|
||||
for _, c := range magazine {
|
||||
if c < 'a' || c > 'z' {
|
||||
continue
|
||||
}
|
||||
counts[int(c)-int('a')]++
|
||||
}
|
||||
for _, c := range ransomNote {
|
||||
if c < 'a' || c > 'z' {
|
||||
continue
|
||||
}
|
||||
offset := int(c) - int('a')
|
||||
counts[offset]--
|
||||
if counts[offset] < 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var _ = canConstruct
|
||||
Loading…
Add table
Add a link
Reference in a new issue