-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeItAnagram.java
33 lines (28 loc) · 1009 Bytes
/
makeItAnagram.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String src = (in.nextLine());
String tar = in.nextLine();
int length = 0;
Map<Character, Integer> an = new HashMap <Character, Integer>();
for (int i = 0; i < src.length(); i++){
char c = src.charAt(i);
if (an.containsKey(c))
an.put(c, an.get(c) + 1);
else
an.put(c, 1);
}
for (int j = 0; j < tar.length(); j++){
char c = tar.charAt(j);
if (an.containsKey(c) && an.get(c) != 0 ) {
an.put(c, an.get(c) - 1);
length += 2;
}
}
System.out.println((src.length()+tar.length())-length);
}