-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirst.java
More file actions
26 lines (24 loc) · 785 Bytes
/
First.java
File metadata and controls
26 lines (24 loc) · 785 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
import java.util.HashSet;
public class First {
public static void main(String[] args) {
// System.out.println("hello world");
lastNonEmptyString("aabcbbca");
}
public static String lastNonEmptyString(String s) {
StringBuilder str=new StringBuilder(s);
StringBuilder res=new StringBuilder(s);
while(!str.isEmpty()){
HashSet<Character> h=new HashSet<>();
res=new StringBuilder(str.toString());
for(int i=0;i<str.length();i++){
char x=str.charAt(i);
if(!h.contains(x)){
h.add(x);
str.deleteCharAt(i);
System.out.println(str);
}
}
}
return res.toString();
}
}