Skip to content

Commit 89fdbe7

Browse files
committed
Create AnagramOfPalindrome
1 parent a19bfc1 commit 89fdbe7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

0 commit comments

Comments
 (0)