zoukankan      html  css  js  c++  java
  • leetcode-1160

    套路题,难点在于数组处理字母,准确是可能想不到,容易滥用map,map在数据量小的时候真心不推荐使用。

    func count(word string) []int {
        counter := make([]int, 26)
        for i := 0; i < len(word); i++ {
            c := word[i]
            counter[c - 'a']++
        }
        return counter
    }
    
    func contain(chars_counter []int, word_counter []int) bool {
        for i := 0; i < 26; i++ {
            if chars_counter[i] < word_counter[i] {
                return false
            }
        }
        return true
    }
    
    func countCharacters(words []string, chars string) int {
        res := 0
        chars_counter := count(chars)
        for _, word := range words {
            word_counter := count(word)
            if contain(chars_counter, word_counter) {
                res += len(word)
            }
        }
        return res
    }

    end

    一个没有高级趣味的人。 email:hushui502@gmail.com
  • 相关阅读:
    顺时针
    true
    td
    确定删除
    on("submit",)
    float:right
    css中:hover空格
    磁盘恢复
    一、报表
    二、实践与视频解决方案
  • 原文地址:https://www.cnblogs.com/CherryTab/p/12514652.html
Copyright © 2011-2022 走看看