-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmallestSubSeqUniq.java
More file actions
38 lines (31 loc) · 978 Bytes
/
smallestSubSeqUniq.java
File metadata and controls
38 lines (31 loc) · 978 Bytes
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
class Main {
public static void main(String[] args) {
Solution result = new Solution();
System.out.println(result.smallestSubsequence("ecbacba"));
}
}
class Solution {
public String smallestSubsequence(String text) {
HashMap<String, Integer> charFreq = new HashMap<>();
char[] textArr = text.toCharArray();
for (char c : textArr) {
if (charFreq.containsKey(c)) {
charFreq.put(c, charFreq.get(c) + 1);
} else {
charFreq.put(c, 1);
}
}
System.out.println(charFreq);
return charFreq;
}
}
// import org.apache.lucene.index.IndexSorter;
// class Solution {
// public String smallestSubsequence(String text) {
// Set<String> textSet = new HashSet<String>(Arrays.asList(text.split("",
// text.length())));
// IndexSorter indexer = new IndexSorter();
// String textResult = String.join("", textSet);
// return textResult;
// }
// }