DP Solution || Unique approach || Clean Code || Beats 90%
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution \n{\n    public static int mod = (int) (1e9 + 7);\n\n    public int countOfPairs(final int[] nums) \n    {\n        final int n = nums.length;\n        final int[][] dp = new int[n + 1][];\n\n        for (int i = 0; i < n; i++) \n        {\n            dp[i] = new int[nums[i] + 1];\n        }\n\n        dp[n] = new int[nums[n - 1] + 1];\n\n        for (int i = 0; i <= nums[n - 1]; i++) \n        {\n            dp[n][i] = 1;\n        }\n\n        for (int i = n - 1; i >= 0; i--) \n        {\n            for (int j = nums[i]; j >= 0; j--) \n            {\n                final int sol1 = (j + 1 <= nums[i] ? dp[i][j + 1] : 0);\n                \n                int sol2 = 0;\n                \n                if ((i + 1) == n) \n                {\n                    sol2 = dp[i + 1][j];\n                }\n                else if(j <= nums[i + 1])\n                {\n                     if (nums[i] < nums[i + 1])\n                     {\n                        final int temp = nums[i] - j;\n\n                        sol2 = dp[i + 1][nums[i + 1] - temp];\n                     }\n                     else sol2 = dp[i + 1][j];\n                }\n\n                dp[i][j] = (sol1 + sol2) % mod;\n            }\n        }\n\n        return dp[0][0];\n    }\n}\n```
['Java']