-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathEmptyRoom.java
More file actions
41 lines (35 loc) · 1.07 KB
/
Copy pathEmptyRoom.java
File metadata and controls
41 lines (35 loc) · 1.07 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
import java.util.*;
import java.util.LinkedList;
/**
* Created by dheeraj on 12/20/14.
*/
public class EmptyRoom {
private List<Character> roomList = new LinkedList<Character>();
private List<Character> nonroomList = new LinkedList<Character>();
String string;
int numRooms;
public EmptyRoom(String string, int numRooms) {
this.string = string;
this.numRooms = numRooms;
}
private void findAnswer() {
char data;
for (int x = 0; x < string.length(); x++) {
data = string.charAt(x);
if(roomList.contains(data)){
roomList.remove(roomList.indexOf(data));
}else if(roomList.size() < numRooms){
roomList.add(data);
}else if(nonroomList.contains(data)){
//do nothig
}else{
nonroomList.add(data);
}
}
System.out.println(nonroomList.size());
}
public static void main(String[] args){
EmptyRoom emptyRoom = new EmptyRoom("ABCBCA",1);
emptyRoom.findAnswer();
}
}