题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
package main import ( "bufio" "fmt" "math" "os" ) func main() { delLeastByte() } func delLeastByte() { var ( store [26]int input []byte min = math.MaxInt32 res []byte ) in := bufio.NewScanner(os.Stdin) in.Scan() input = in.Bytes() for i := 0; i < len(input); i++ { store[input[i]-byte('a')]++ } for i := 0; i < len(store); i++ { if store[i] < min && store[i] > 0 { min = store[i] } } for i := 0; i < len(input); i++ { if store[input[i]-byte('a')] != min { res = append(res, input[i]) } } fmt.Println(string(res)) }