-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion2405.java
More file actions
47 lines (42 loc) · 939 Bytes
/
Copy pathQuestion2405.java
File metadata and controls
47 lines (42 loc) · 939 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
39
40
41
42
43
44
45
46
47
/*
Author: Ananthanarayanan R
Section: Algorithms
Question: 2405
*/
import java.util.*;
public class Question2405
{
public static int partitionString(String s)
{
List<String> result = new ArrayList<>();
for(int i = 0;i<s.length();i++)
{
int count = 0;
if(result.size()==0)
result.add(""+s.charAt(i));
else
{
//check if result(result.size()-1).contains(s.charAt(i))
if(result.get(result.size()-1).contains(""+s.charAt(i))) // if present
{
result.add(""+s.charAt(i));
}
else
{
String temp = result.get(result.size()-1);
temp+=s.charAt(i);
result.remove(result.size()-1);
result.add(temp);
}
}
}
System.out.println(result);
return result.size();
}
public static void main(String[] args)
{
String s = "hdklqkcssgxlvehva";
int result = partitionString(s);
System.out.println(result);
}
}