Skip to content

Commit

Permalink
20180617
Browse files Browse the repository at this point in the history
  • Loading branch information
pwxcoo committed Jun 17, 2018
1 parent 16403fd commit f8caf20
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
44 changes: 44 additions & 0 deletions 2018-06/2018-06-17/leetcode855.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class ExamRoom {
int N;
TreeSet<Integer> students;

public ExamRoom(int N) {
this.N = N;
students = new TreeSet();
}

public int seat() {
int student = 0;
if (students.size() > 0) {
int dist = students.first();
Integer prev = null;
for (Integer s: students) {
if (prev != null) {
int d = (s - prev) / 2;
if (d > dist) {
dist = d;
student = prev + d;
}
}
prev = s;
}

// Considering the right-most seat.
if (N - 1 - students.last() > dist)
student = N - 1;
}

students.add(student);
return student;
}

public void leave(int p) {
students.remove(p);
}
}
/**
* Your ExamRoom object will be instantiated and called as such:
* ExamRoom obj = new ExamRoom(N);
* int param_1 = obj.seat();
* obj.leave(p);
*/
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,7 @@ Accept Game
- leetcode795
### 2018-06-13
- leetcode848 / 数据范围
- leetcode851 / dfs + 记忆化搜索
### 2018-06-14
- leetcode851 / dfs + 记忆化搜索
### 2018-06-17
- leetcode855 / set

0 comments on commit f8caf20

Please sign in to comment.