# 1418. 点菜展示表

#### 2021-07-06 LeetCode每日一题

``````输入：orders = [["David","3","Ceviche"],["Corina","10","Beef Burrito"],["David","3","Fried Chicken"],["Carla","5","Water"],["Carla","5","Ceviche"],["Rous","3","Ceviche"]]

Table,Beef Burrito,Ceviche,Fried Chicken,Water
3    ,0           ,2      ,1            ,0
5    ,0           ,1      ,0            ,1
10   ,1           ,0      ,0            ,0

``````输入：orders = [["James","12","Fried Chicken"],["Ratesh","12","Fried Chicken"],["Amadeus","12","Fried Chicken"],["Adam","1","Canadian Waffles"],["Brianna","1","Canadian Waffles"]]

``````输入：orders = [["Laura","2","Bean Burrito"],["Jhon","2","Beef Burrito"],["Melissa","2","Soda"]]

• 1 <= orders.length <= 5 * 10^4
• orders[i].length == 3
• 1 <= customerNamei.length, foodItemi.length <= 20
• customerNamei 和 foodItemi 由大小写英文字母及空格字符 ' ' 组成。
• tableNumberi 是 1 到 500 范围内的整数。

``````class Solution {
public List<List<String>> displayTable(List<List<String>> orders) {
List<List<String>> res = new ArrayList<>();
Map<String, Integer> map = new HashMap<>();
// 存放餐品名称，无重复
Set<String> foodItems = new TreeSet<>();
// 存放餐桌，无重复,Integer类型，才能正常排序
Set<Integer> tables = new TreeSet<>();

for (int i = 0; i < orders.size(); i++) {
List<String> list = orders.get(i);
// 桌号 + 餐品名称组成键
String key = list.get(1) + "_" + list.get(2);
map.put(key, map.getOrDefault(key, 0) + 1);
}

// 标题
for (Integer table : tables) {
List<String> row = new ArrayList<>();
for (String foodItem : foodItems) {
String key = table + "_" + foodItem;
Integer value = map.get(key) == null ? 0 : map.get(key);