Created
June 20, 2018 10:56
-
-
Save lokeshh/36ea47d791ea95e5909ee9d02bd22967 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public static int findAnagram(int[] input1, int input2) { | |
int[] num_dic = new int[10]; | |
boolean match = true; | |
for (int i = 0; i < input2; i++) { | |
char[] n1 = Integer.toString(input1[i]).toCharArray(); | |
for (int j = i+1; j < input2; j++) { | |
char[] n2 = Integer.toString(input1[j]).toCharArray(); | |
int[] digit_count = new int[10]; | |
int[] digit_count2 = new int[10]; | |
for (char ch : n1) { | |
digit_count[Character.getNumericValue(ch)] += 1; | |
} | |
for (char ch : n2) { | |
digit_count2[Character.getNumericValue(ch)] += 1; | |
} | |
for (int x = 0; x < 10; x++) { | |
if (digit_count[x] != digit_count2[x]) { | |
match = false; | |
break; | |
} | |
} | |
// System.out.println(i + " " + j + match); | |
if (match == false) { | |
match = true; | |
continue; | |
} | |
int anagrams = 2; | |
match = true; | |
for (int k = 0; k < input2; k++) { | |
if ((k != i) && (k != j)) { | |
digit_count2 = new int[10]; | |
n2 = Integer.toString(input1[k]).toCharArray(); | |
for (char ch : n2) { | |
digit_count2[Character.getNumericValue(ch)] += 1; | |
} | |
for (int l = 0; l < 10; l++) { | |
if (digit_count[l] != digit_count2[l]) { | |
match = false; | |
break; | |
} | |
} | |
// System.out.println(digit_count2[1]); | |
if (match == false) { | |
match = true; | |
continue; | |
} | |
anagrams += 1; | |
} | |
} | |
return anagrams; | |
} | |
} | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment