Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. static boolean isAnagram(String A,String B) {
  2. HashMap<Character, Integer> map = new HashMap<Character, Integer>();
  3. List<HashMap<Character, Integer>> listA = new ArrayList<HashMap<Character, Integer>>();
  4. List<HashMap<Character, Integer>> listB = new ArrayList<HashMap<Character, Integer>>();
  5. for (int i = 0; i < A.length(); i++) {
  6. Character a = A.charAt(i);
  7. map = new HashMap<Character, Integer>();
  8. map.put(a.charValue(), a.hashCode());
  9. listA.add(map);
  10. }
  11. for (int i = 0; i < B.length(); i++) {
  12. Character a = B.charAt(i);
  13. map = new HashMap<Character, Integer>();
  14. map.put(a.charValue(), a.hashCode());
  15. listB.add(map);
  16. }
  17.  
  18.  
  19. int valA = 0;
  20. int valB = 0;
  21. boolean result = true;
  22. for (HashMap<Character, Integer> hashA : listA) {
  23. for (Character charA : hashA.keySet()) {
  24. valA +=hashA.get(charA);
  25. valB = 0;
  26. for (HashMap<Character, Integer> hashB : listB) {
  27. for (Character charB : hashB.keySet()) {
  28. valB +=hashB.get(charB);
  29. if(hashA.get(charB) == (null)){
  30. result = false;
  31. break;
  32. }
  33. }
  34. }
  35. }
  36. }
  37. return
  38. (valA == valB && !result);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement