Created
October 26, 2014 10:07
-
-
Save lethe2211/ae41b61353ae2ee2f366 to your computer and use it in GitHub Desktop.
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
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