Skip to content

Commit 22ad951

Browse files
committed
Create ransom-note.go
1 parent 043d8c2 commit 22ad951

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

ransom-note.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//https://leetcode.com/problems/ransom-note/
2+
3+
package leetcode_solutions_golang
4+
5+
func canConstruct(ransomNote string, magazine string) bool {
6+
totalA := [26]int{}
7+
for _, c := range ransomNote {
8+
totalA[c-'a']++
9+
}
10+
11+
totalB := [26]int{}
12+
for _, c := range magazine {
13+
totalB[c-'a']++
14+
}
15+
16+
for key, i := range totalA {
17+
if i > totalB[key] {
18+
return false
19+
}
20+
}
21+
22+
return true
23+
}

0 commit comments

Comments
 (0)