849. Maximize Distance to Closest Person
1 | class Solution { |
是exam room的低阶版. 记录上一个seated的位置即可. 需要注意edge case, 也就是当第0个位置没人坐或者在某个位置后直到数组结束都是空位. 这两种情况对应第6行和第10行的操作.
时间复杂度: O(n)
空间复杂度: O(1)
Insist on doing small things, then witness the magic
1 | class Solution { |
是exam room的低阶版. 记录上一个seated的位置即可. 需要注意edge case, 也就是当第0个位置没人坐或者在某个位置后直到数组结束都是空位. 这两种情况对应第6行和第10行的操作.
时间复杂度: O(n)
空间复杂度: O(1)