File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ package codility;
2+ 
3+ /**
4+  *
5+  * @author David Daniel Kurtz <
[email protected] >
6+  */
7+ public class AnagramOfPalindrome {
8+     public int result(String S) {
9+         int uniqueCount = 0;
10+         String newS = S;
11+         int i = 0;
12+         while (newS.length() > 0) {
13+             int currentCount = 0;
14+             for (int j = 0; j < newS.length(); j++) {
15+                 if (S.charAt(i) == newS.charAt(j)) {
16+                     currentCount++;
17+                 }
18+             }
19+             newS = newS.replaceAll(String.valueOf(S.charAt(i)), "");
20+             if ((currentCount % 2) == 1) {
21+                 uniqueCount++;
22+             }
23+             i++;
24+         }
25+         if (uniqueCount > 1) {
26+             return 0;
27+         } else {
28+             return 1;
29+         }
30+     }
31+     
32+     public static void main(String[] args) {
33+         System.out.println(new AnagramOfPalindrome().result("dooernedeevrvn"));
34+         System.out.println(new AnagramOfPalindrome().result("kakya"));
35+         System.out.println(new AnagramOfPalindrome().result("aabcba"));
36+     }
37+ }
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments