Simple Two Pointer Clean Approach
Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) \n\n# Code
# Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    int MOD =  1_000_000_007;\n\n    public int maxSum(int[] nums1, int[] nums2) {\n        int len1 = nums1.length;\n        int len2 = nums2.length;\n\n        long sum1 = 0, sum2 = 0;\n        int i = 0, j = 0;\n        while (i < len1 || j < len2) {\n            if (i < len1 && (j == len2 || nums1[i] < nums2[j])) {\n                sum1 += nums1[i++];\n            } else if (j < len2 && (i == len1 || nums1[i] > nums2[j])) {\n                sum2 += nums2[j++];\n            } else {\n                sum2 = Math.max(sum1, sum2) + nums1[i];\n                sum1 = sum2;\n                i++;\n                j++;\n            }\n        }\n        return (int) (Math.max(sum1, sum2) % MOD);\n    }\n}\n```
['Array', 'Math', 'Two Pointers', 'Dynamic Programming', 'Greedy', 'Java']