-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathSolution.java
33 lines (26 loc) · 1.06 KB
/
Solution.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.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Solution {
private static final Scanner scanner = new Scanner(System.in);
// Complete the makeAnagram function below.
static int makeAnagram(String a, String b) {
Map<Integer, Integer> map = new HashMap<>();
a.chars().forEach(c -> map.put(c, map.getOrDefault(c, 0) + 1));
b.chars().forEach(c -> map.put(c, map.getOrDefault(c, 0) - 1));
return map.values().stream().reduce(0, (subtotal, value) -> subtotal + Math.abs(value));
}
public static void main(String[] args) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
String a = scanner.nextLine();
String b = scanner.nextLine();
int res = makeAnagram(a, b);
bufferedWriter.write(String.valueOf(res));
bufferedWriter.newLine();
bufferedWriter.close();
scanner.close();
}
}