public int[] exclusiveTime(int n, List<String> logs) {
if (n <= 0 || logs == null || logs.size() == 0) {
Stack<Integer> stack = new Stack();
// preTime is the start of interval
for (String log : logs) {
String[] parts = log.split(":");
int id = Integer.parseInt(parts[0]);
curTime = Integer.parseInt(parts[2]);
if (parts[1].equals("start")) {
// curTime is the start of next interval, it doesn't belong to
// current interval, should not count it here
res[stack.peek()] += curTime - preTime;
// curTime is the end of current interval, we should count it
res[stack.pop()] += curTime - preTime + 1;
// Update preTime to start of next interval by plus 1