第二题: public static int maxSum (String[] words) { // write code here List<Set<Character>> list = new ArrayList<>(); for (int i = 0; i < words.length; i++) { Set<Character> set = new HashSet<>(); for (int j = 0; j < words[i].length(); j++) { set.add(words[i].charAt(j)); } list.add(set); } int max=0,now=0; for (int i = 0; i < list.size()-1; i++) { for (int j = i+1; j < list.size(); j++) { Set<Character> set = new HashSet<>(); set.addAll(list.get(i)); set.addAll(list.get(j)); now = set.size(); if (now == list.get(i).size()+list.get(j).size()){ max = max>now?max:now; } } } return max; }
点赞 评论

相关推荐

喵_coding:项目太烂了外卖+点评啊 而且寒假实习差不多到时候了 hc没多少了 要实在想要找那只能投投大厂试试了
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务