MakeAnagram
This commit is contained in:
parent
019f62504b
commit
322aa305a3
Binary file not shown.
@ -1,12 +1,42 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class AnagramPeriod {
|
||||
|
||||
public static void main(String[] args) {
|
||||
getAnagramPeriod("ababbaab");
|
||||
Scanner sc = new Scanner(System.in);
|
||||
String a = sc.nextLine();
|
||||
String b = sc.nextLine();
|
||||
sc.close();
|
||||
|
||||
int totalDel = makeAnagram(a, b);
|
||||
System.out.println(totalDel);
|
||||
|
||||
}
|
||||
|
||||
private static void getAnagramPeriod(String input_str) {
|
||||
int n = input_str.length();
|
||||
System.out.println(n);
|
||||
private static int makeAnagram(String strOne, String strTwo) {
|
||||
// bacdc
|
||||
// dcbac
|
||||
// bacdc
|
||||
// dcbad
|
||||
|
||||
int[] a_frequency = new int[26]; // 26 numbers of letters in the alphabet.
|
||||
int[] b_frequency = new int[26]; // 26 numbers of letters in the alphabet.
|
||||
|
||||
// populate the frequence array for String strOne
|
||||
for (char c : strOne.toCharArray()) {
|
||||
a_frequency[c - 'a']++;
|
||||
}
|
||||
|
||||
// populate the frequence array for String strTwo
|
||||
for (char c : strTwo.toCharArray()) {
|
||||
b_frequency[c - 'a']++;
|
||||
}
|
||||
|
||||
// calculate the total number of deletions needed
|
||||
int deletion = 0;
|
||||
for (int i = 0; i < 26; i++) {
|
||||
deletion += Math.abs(a_frequency[i] - b_frequency[i]);
|
||||
}
|
||||
return deletion;
|
||||
}
|
||||
}
|
||||
|
||||
4
test-results/.last-run.json
Normal file
4
test-results/.last-run.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"status": "failed",
|
||||
"failedTests": []
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user