classSolution: defreformat(self, s: str) -> str: res = "" ch="" num="" for x in s: if x>='a'and x<='z': ch += x else: num += x if abs(len(ch)-len(num)) >= 2 : return"" else: i=0 while i<min(len(ch),len(num)) : if len(ch)>len(num) : res += ch[i]+num[i] else: res += num[i]+ch[i] i+=1 if i>=len(ch) and i<len(num) : res += num[i] elif i>=len(num) and i<len(ch) : res += ch[i] return res
from collections import Counter classSolution: defdisplayTable(self, orders: List[List[str]]) -> List[List[str]]: food_set = set() table_set = set() table_food_dict = Counter() res = [] for order in orders: _,table,food = order table = int(table) table_food_dict[(table, food)] += 1 food_set.add(food) table_set.add(table) food_set= sorted(list(food_set)) table_set= sorted(list(table_set)) res.append(['Table']+food_set) for table in table_set: line = [] line.append(str(table)) for food in food_set: line.append(str(table_food_dict[(table,food)])) res.append(line) return res
from collections import defaultdict import queue classSolution: defminNumberOfFrogs(self, croakOfFrogs: str) -> int: map_ = {'c':0,'r':1,'o':2,'a':3,'k':4} num_list = [0] * 5 res = 0 for x in croakOfFrogs: num = map_[x] if num == 0: if num_list[4] <= 0: res += 1 num_list[num] += 1 else : num_list[4] -= 1 num_list[0] += 1 else: t = (num + 4) % 5 num_list[t] -= 1 num_list[num] += 1 for i in range(5): if num_list[i] < 0: return-1 for i in range(4): if num_list[i] < 0: return-1 return res