You are viewing a single comment's thread. Return to all comments →
JAVA
public static int birthday(List<Integer> s, int d, int m) { int n = s.size(); int count = 0; int sum = 0; for (int i = 0; i < m; i++) { sum += s.get(i); } if (sum == d) count++; for (int i = m; i < n; i++) { sum += s.get(i); sum -= s.get(i - m); if (sum == d) count++; } return count; }
Seems like cookies are disabled on this browser, please enable them to open this website
Subarray Division
You are viewing a single comment's thread. Return to all comments →
Sliding window technique O(n)
JAVA