代码实现
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实现)
原文地址:http://blog.csdn.net/books1958/article/details/46785785