标签:删除 -- 英文字母 var lan delete 等于 article ack
代码实现
package huawei import ( "fmt" ) func Test4Base() { s := "abcfbcca" result := deleteMinChars(s) fmt.Println(result) } func deleteMinChars(s string) string { countMap := make(map[rune]int, 0) //统计出现次数 for _, v := range s { countMap[v]++ } //查找最少次数 var minCount int for _, v := range countMap { if minCount == 0 || v < minCount { minCount = v } } //删除字符串中出现次数为minCount的字符 for i := len(s) - 1; i >= 0; i-- { if countMap[rune(s[i])] == minCount { s = s[:i] + s[i+1:] } } return s }
算法基础:删除字符串中出现次数最少的字符(Golang实现)
标签:删除 -- 英文字母 var lan delete 等于 article ack
原文地址:http://www.cnblogs.com/cxchanpin/p/7357064.html