Created
May 1, 2018 00:32
-
-
Save xpaulnim/297b85aa84cd6aa0be86d1dccefb540c to your computer and use it in GitHub Desktop.
MergeStrings java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static String MergeStrings(String[] strings) { | |
Map<Character, Integer> charCount = new HashMap<>(); | |
for (String str : strings) { | |
for (int i = 0; i < str.length(); i++) { | |
char c = str.charAt(i); | |
if (Character.isAlphabetic(c)) { | |
charCount.merge(c, 1, (a, b) -> a + b); | |
} | |
} | |
} | |
StringBuilder stringBuilder = new StringBuilder(); | |
for (Map.Entry<Character, Integer> entry : charCount.entrySet()) { | |
stringBuilder.append(new String(new char[entry.getValue()]).replace("\0", entry.getKey().toString())); | |
} | |
return stringBuilder.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment