aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2023-12-02 03:30:56 +0000
committerterminaldweller <devi@terminaldweller.com>2023-12-02 03:30:56 +0000
commit50b4275d6e4084638bd24758a6ca1d3c49321173 (patch)
tree3f9f070cd2ccb809d757dbde33bba2b7e641c99a
parent502 (diff)
downloadleetcode-50b4275d6e4084638bd24758a6ca1d3c49321173.tar.gz
leetcode-50b4275d6e4084638bd24758a6ca1d3c49321173.zip
1160
-rw-r--r--1160/main.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/1160/main.go b/1160/main.go
new file mode 100644
index 0000000..84e9c21
--- /dev/null
+++ b/1160/main.go
@@ -0,0 +1,26 @@
+package main
+
+func countCharacters(words []string, chars string) int {
+ var cnt int
+ charMap := make(map[rune]int)
+ for _, v := range chars {
+ charMap[v]++
+ }
+ for _, v := range words {
+ tmpMap := make(map[rune]int)
+ for _, vv := range v {
+ tmpMap[vv]++
+ }
+ var flag bool
+ for k, v := range tmpMap {
+ if charMap[k] < v {
+ flag = true
+ break
+ }
+ }
+ if !flag {
+ cnt += len(v)
+ }
+ }
+ return cnt
+}