Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static long countInvestablePeriods(int[] price, int maxPrice, int minPrice) {
- int n = price.length;
- long count = 0;
- for (int i = 0; i < n; i++) {
- int max = price[i];
- int min = price[i];
- for (int j = i + 1; j < n; j++) {
- max = Math.max(max, price[j]);
- min = Math.min(min, price[j]);
- if (max == maxPrice && min == minPrice) {
- count++;
- }
- }
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement