Skip to content

Instantly share code, notes, and snippets.

@lethe2211
Created October 26, 2014 10:07
Show Gist options
  • Save lethe2211/ae41b61353ae2ee2f366 to your computer and use it in GitHub Desktop.
Save lethe2211/ae41b61353ae2ee2f366 to your computer and use it in GitHub Desktop.
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String str1 = sc.next();
String str2 = sc.next();
HashMap<Character, Integer> count1 = new HashMap<Character, Integer>();
HashMap<Character, Integer> count2 = new HashMap<Character, Integer>();
if (str1.length() != str2.length()) {
System.out.println("NO");
} else {
for (int i = 0; i < str1.length(); i++) {
Character c1 = str1.charAt(i);
Character c2 = str2.charAt(i);
if (!count1.containsKey(c1)) {
count1.put(c1, 0);
}
count1.put(c1, count1.get(c1) + 1);
if (!count2.containsKey(c2)) {
count2.put(c2, 0);
}
count2.put(c2, count2.get(c2) + 1);
}
Boolean flag = true;
for (Map.Entry<Character, Integer> e : count1.entrySet()) {
Character key = e.getKey();
if (!(count2.containsKey(key) && e.getValue() == count2
.get(key))) {
flag = false;
}
}
if (flag) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment