题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
def inputstr(): str1 = input('') while True: if len(str1) < 0 or len(str1) >20: str1 = input('') else: str1.lower() return str1 def delMinCont(str1): strCount = [] strlist = [] for i in str1: strCount.append(str1.count(i)) strlist.append(i) # print(strCount) # print(strlist) index = 0 for i in strCount: if i == min(strCount): # print(i) # print(strlist[index]) # 删除操作的时候索引会向前移动一位,所以此时index不用+1 del strlist[index] continue index =index + 1 # print(index) return ''.join(strlist) str1 = inputstr() print(delMinCont(str1))