-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString_14.java
More file actions
56 lines (46 loc) · 1.42 KB
/
Copy pathString_14.java
File metadata and controls
56 lines (46 loc) · 1.42 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package HuaweiCoding;
import java.util.LinkedHashMap;
import java.util.Scanner;
import java.util.Map.Entry;
public class String_14 {
public static String deleteString(String inputLine) {
LinkedHashMap<Character,Integer> linkedHashMap=new LinkedHashMap<>();;
for(int i=0;i<inputLine.length();i++) {
char item = inputLine.charAt(i);
if(linkedHashMap.containsKey(item)) {
linkedHashMap.put(item, linkedHashMap.get(item)+1);
}else {
linkedHashMap.put(item, 1);
}
}
int counts=Integer.MAX_VALUE;
for (Entry<Character,Integer> keyValue : linkedHashMap.entrySet()) {
if(keyValue.getValue()<=counts) {
counts=keyValue.getValue();
}
}
StringBuilder sb=new StringBuilder();
for(Entry<Character, Integer> keyValue : linkedHashMap.entrySet()) {
if(keyValue.getValue()==counts) {
sb.append(keyValue.getKey());
}
}
String resultStr=sb.toString();
StringBuilder deleteStr=new StringBuilder();
for(int i=0;i<inputLine.length();i++) {
char itemValue = inputLine.charAt(i);
if(!(resultStr.contains(itemValue+""))) {
deleteStr.append(itemValue);
}
}
return deleteStr.toString();
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) {
String nextLine = sc.nextLine();
String deleteString = deleteString(nextLine);
System.out.println(deleteString);
}
}
}