- Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathSolution495.java
More file actions
Latest commit
executable file
·27 lines (25 loc) · 777 Bytes
/
Copy pathSolution495.java
File metadata and controls
executable file
·27 lines (25 loc) · 777 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
/**
* Created by slade on 2019/6/26.
*/
publicclassSolution495 {
publicintfindPoisonedDuration(int[] timeSeries, intduration) {
if (timeSeries.length==0) return0;
intstart = timeSeries[0];
intcurSum = 0;
for (inti = 1; i < timeSeries.length; i++) {
if (timeSeries[i] - start <= duration - 1) {
curSum += timeSeries[i] - start;
start = timeSeries[i];
} else {
curSum += duration;
start = timeSeries[i];
}
}
returncurSum+duration;
}
publicstaticvoidmain(String[] args) {
Solution495s = newSolution495();
int[] a = {};
System.out.println(s.findPoisonedDuration(a,2));
}
}