View difference between Paste ID: EwgtAmch and
SHOW:
|
|
- or go back to the newest paste.
1 | - | |
1 | + | public class Anagram { |
2 | int isAnagramOfPalindrome ( String S ) { | |
3 | char [] tab = S.toCharArray(); | |
4 | HashMap<Character,Integer> map = new HashMap<Character,Integer>(); | |
5 | for(int i = 0; i < tab.length ; i++){ | |
6 | Character tmp = tab[i]; | |
7 | if(map.containsKey(tmp)){ | |
8 | Integer j = map.get(tmp); | |
9 | Integer jj = j+1; | |
10 | map.put(tmp, jj); | |
11 | ||
12 | } | |
13 | else{ | |
14 | map.put(tmp, 0); | |
15 | } | |
16 | } | |
17 | int a = 0; | |
18 | Collection col = map.values(); | |
19 | Integer [] val = (Integer[]) col.toArray(); | |
20 | for(int i = 0 ; i < val.length ; i++){ | |
21 | int iii = val[i].intValue(); | |
22 | if((val[i].intValue()%2) == 0){ | |
23 | ||
24 | } | |
25 | else{ | |
26 | a++; | |
27 | } | |
28 | } | |
29 | if(a==1){ | |
30 | return 1; | |
31 | } | |
32 | else{ | |
33 | return 0; | |
34 | } | |
35 | } | |
36 | } |