Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static boolean isAnagram(String A,String B) {
- HashMap<Character, Integer> map = new HashMap<Character, Integer>();
- List<HashMap<Character, Integer>> listA = new ArrayList<HashMap<Character, Integer>>();
- List<HashMap<Character, Integer>> listB = new ArrayList<HashMap<Character, Integer>>();
- for (int i = 0; i < A.length(); i++) {
- Character a = A.charAt(i);
- map = new HashMap<Character, Integer>();
- map.put(a.charValue(), a.hashCode());
- listA.add(map);
- }
- for (int i = 0; i < B.length(); i++) {
- Character a = B.charAt(i);
- map = new HashMap<Character, Integer>();
- map.put(a.charValue(), a.hashCode());
- listB.add(map);
- }
- int valA = 0;
- int valB = 0;
- boolean result = true;
- for (HashMap<Character, Integer> hashA : listA) {
- for (Character charA : hashA.keySet()) {
- valA +=hashA.get(charA);
- valB = 0;
- for (HashMap<Character, Integer> hashB : listB) {
- for (Character charB : hashB.keySet()) {
- valB +=hashB.get(charB);
- if(hashA.get(charB) == (null)){
- result = false;
- break;
- }
- }
- }
- }
- }
- return
- (valA == valB && !result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement