forked from anand-rygbee/rygbeeSkillsTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SkillTest1
51 lines (46 loc) · 1.01 KB
/
SkillTest1
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
package test1;
import java.util.ArrayList;
public class SkillTest1 {
public String dupliRemove(String str)
{
ArrayList<String> strings = new ArrayList<String>();
for (int i = 0; i < str.length(); i++) {
strings.add(str.substring(i, i+1));
}
for (int i = 0; i < strings.size();i++)
{
for(int j = i+1;j < strings.size();j++)
{
if(strings.get(i).equals(strings.get(j)))
{ strings.remove(j);
j--;}
}
}
str="";
for (int i = 0; i < strings.size(); i++) {
str=str+strings.get(i);
}
return str;
}
public String consecutiveDuplicateRemove(String str)
{
ArrayList<String> strings = new ArrayList<String>();
for (int i = 0; i < str.length(); i++) {
strings.add(str.substring(i, i+1));
}
for (int i = 0; i < strings.size()-1;)
{
if(strings.get(i).equals(strings.get(i+1)))
{ strings.remove(i);
}
else
{i++;
}
}
str="";
for (int i = 0; i < strings.size(); i++) {
str=str+strings.get(i);
}
return str;
}
}