Ad
Strings
Data Structures
Strings
Code
Diff
  • import java.util.*;
    
    public class Kata {
    
    public static String keyAlphabet(String str) {
    
      String[] arr = str.split(" ");
      List<String> listKey = new ArrayList<String>();
      PriorityQueue<String> listValue = new PriorityQueue<>();
      TreeMap<String, String> alphabet = new TreeMap<>();
      
      for (String item : arr) {
        if (item.length() == 1 && item.charAt(0) >= 'a' && item.charAt(0) <= 'z') {
          listKey.add(item);
        } else {
          listValue.add(item);
        }
      }
      
      List<String> values = new ArrayList<>(listValue);
      
      for (String value : values) {
        for (String s : listKey) {
          if (value.contains(s)) {
            if (alphabet.containsKey(s)) {
              alphabet.put(s, alphabet.get(s) + "," + value);
            } else {
              alphabet.put(s, value);
            }
          }
        }
      }
      
      
      
      
      
      
      
      return "";
      }
    
    }
    • import java.util.*;
    • public class Kata {
    • public static String keyAlphabet(String str) {
    • String[] arr = str.split(" ");
    • List<String> listKey = new ArrayList<String>();
    • PriorityQueue<String> listValue = new PriorityQueue<>();
    • TreeMap<String, String> alphabet = new TreeMap<>();
    • for (String item : arr) {
    • if (item.length() == 1 && item.charAt(0) >= 'a' && item.charAt(0) <= 'z') {
    • listKey.add(item);
    • } else {
    • listValue.add(item);
    • }
    • }
    • List<String> values = new ArrayList<>(listValue);
    • for (String value : values) {
    • for (String s : listKey) {
    • if (value.contains(s)) {
    • if (alphabet.containsKey(s)) {
    • alphabet.put(s, alphabet.get(s) + "," + value);
    • } else {
    • alphabet.put(s, value);
    • }
    • }
    • }
    • }
    • return "";
    • }
    • }
Strings
Code
Diff
  • import java.util.*;
    
    public class Kata {
    
    public static String keyAlphabet(String str) {
    
      String[] arr = str.split(" ");
      List<String> listKey = new ArrayList<String>();
      PriorityQueue<String> listValue = new PriorityQueue<>();
      TreeMap<String, String> alphabet = new TreeMap<>();
      
      for (String item : arr) {
        if (item.length() == 1 && item.charAt(0) >= 'a' && item.charAt(0) <= 'z') {
          listKey.add(item);
        } else {
          listValue.add(item);
        }
      }
      
      List<String> values = new ArrayList<>(listValue);
      
      
      
      
      
      
      return "";
      }
    
    }
    • import java.util.*;
    • public class Kata {
    • public static String keyAlphabet(String str) {
    • String[] arr = str.split(" ");
    • List<String> listKey = new ArrayList<String>();
    • PriorityQueue<String> listValue = new PriorityQueue<>();
    • TreeMap<String, String> alphabet = new TreeMap<>();
    • for (String item : arr) {
    • if (item.length() == 1 && item.charAt(0) >= 'a' && item.charAt(0) <= 'z') {
    • listKey.add(item);
    • } else {
    • listValue.add(item);
    • }
    • }
    • List<String> values = new ArrayList<>(listValue);
    • return "";
    • }
    • }
Code
Diff
  • import java.util.*;
    
    public class Kata {
    
    public static String keyAlphabet(String str) {
    
      String[] arr = str.split(" ");
      List<String> listKey = new ArrayList<String>();
      PriorityQueue<String> listValue = new PriorityQueue<>();
      TreeMap<String, String> alphabet = new TreeMap<>();
      
      for (String item : arr) {
        if (item.length() == 1 && item.charAt(0) >= 'a' && item.charAt(0) <= 'z') {
          listKey.add(item);
        } else {
          listValue.add(item);
        }
      }
      
      
      return "";
      }
    
    }
    • import java.util.*;
    • public class Kata {
    • public static String keyAlphabet(String str) {
    • String[] arr = str.split(" ");
    • List<String> listKey = new ArrayList<String>();
    • PriorityQueue<String> listValue = new PriorityQueue<>();
    • TreeMap<String, String> alphabet = new TreeMap<>();
    • String[] arr = str.split(" ");
    • List<String> listKey = new ArrayList<String>();
    • PriorityQueue<String> listValue = new PriorityQueue<>();
    • TreeMap<String, String> alphabet = new TreeMap<>();
    • for (String item : arr) {
    • if (item.length() == 1 && item.charAt(0) >= 'a' && item.charAt(0) <= 'z') {
    • listKey.add(item);
    • } else {
    • listValue.add(item);
    • }
    • }
    • return "";
    • }
    • }