Skip to content

Latest commit

 

History

History
31 lines (26 loc) · 806 Bytes

Question_2393.md

File metadata and controls

31 lines (26 loc) · 806 Bytes

LeetCode Records - Question 2393 Count Strictly Increasing Subarrays

Attempt 1: Use the formula: sum of integers

class Solution {
    public long countSubarrays(int[] nums) {
        long totalCount = 0;
        
        long increasingCount = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i - 1]) {
                increasingCount++;
            } else {
                totalCount += getSumOfSubarray(increasingCount);
                increasingCount = 1;
            }
        }
        totalCount += getSumOfSubarray(increasingCount);

        return totalCount;
    }

    private long getSumOfSubarray(long n) {
        return (1 + n) * n / 2;
    }
}
  • Runtime: 2 ms (Beats: 100.00%)
  • Memory: 57.08 MB (Beats: 57.14%)