Skip to content

Commit 27bb9da

Browse files
update 346
1 parent d4e08fa commit 27bb9da

File tree

1 file changed

+4
-8
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-8
lines changed

Diff for: src/main/java/com/fishercoder/solutions/_346.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,13 @@ public MovingAverage(int size) {
2222
}
2323

2424
public double next(int val) {
25-
if (q.size() < max) {
26-
q.offer(val);
27-
sum += val;
28-
return (double) sum / q.size();
29-
} else {
25+
if (q.size() >= max) {
3026
int first = q.pollFirst();
3127
sum -= first;
32-
q.offer(val);
33-
sum += val;
34-
return (double) sum / q.size();
3528
}
29+
sum += val;
30+
q.offer(val);
31+
return (double) sum / q.size();
3632
}
3733
}
3834
}

0 commit comments

Comments
 (0)