public class BianWeiArr { public static void main(String[] args) { Scanner input = new Scanner(System.in); String[] a={"eat","tea","tan","ate","nat","bat"}; System.out.println(groupAnagrams(a)); }
class WordsFrequency { Map<String,Integer> recMap = new HashMap<>(); public WordsFrequency(String[] book) { for(int i=0;i<book.length;i++) { if(!recMap.containsKey(book[i])) { recMap.put(book[i],1); }else { recMap.put(book[i], recMap.get(book[i])+1); } } }
public int get(String word) { if(recMap.containsKey(word)) { return recMap.get(word); } return 0; } }
/** * Your WordsFrequency object will be instantiated and called as such: * WordsFrequency obj = new WordsFrequency(book); * int param_1 = obj.get(word); */
public class OnlyOne { public static void main(String[] args) { Scanner input = new Scanner(System.in); String s=input.next(); System.out.println(firstUniqChar(s)); }
public class ShuDuiHe { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n=input.nextInt(); int[] a=new int[n]; for(int i=0;i<a.length;i++){ a[i]=input.nextInt(); } int target=input.nextInt(); System.out.println(pairSums(a,target)); }
public static List<List<Integer>> pairSums(int[] nums, int target) { List<List<Integer>> ans=new LinkedList<>(); Arrays.sort(nums); //对数组进行排序 int start=0; int end=nums.length-1; for(;start<end;){ int sum = nums[start] + nums[end]; if (sum < target) { //要变大一些 start++; } else if (sum > target){ //要变小一些 end--; } else { //刚好符合 List<Integer> list = new LinkedList<>(); //新成立list集合 list.add(nums[start]); //存进去start和end位置的值 list.add(nums[end]); ans.add(list); //最终结果添加list集合 start++; //缩小范围 end--; } } return ans; }