-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram7.java
More file actions
55 lines (38 loc) · 1.14 KB
/
program7.java
File metadata and controls
55 lines (38 loc) · 1.14 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
/*
316. Remove Duplicate Letters
Medium
6.8K
432
Companies
Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is
the smallest in lexicographical order
among all possible results.
Example 1:
Input: s = "bcabc"
Output: "abc"
Example 2:
Input: s = "cbacdcbc"
Output: "acdb"
*/
package LeetCode_String;
import java.util.ArrayList;
import java.util.List;
public class program7 {
static String removeDuplicateLetters(String s) {
List<Character> ls = new ArrayList<Character>();
String str = "";
for(int i=0;i<s.length();i++){
if(!ls.contains(s.charAt(i))){
ls.add(i, s.charAt(i));
str +=ls.get(i);
}
}
System.out.println(ls);
return str;
}
public static void main(String[] args) {
String s = "bcabc";
String str = removeDuplicateLetters(s);
System.out.println(str);
}
}