Java two pointer solution simple easy to understand O(n) O(1)
\nclass Solution {\n    public int maxSum(int[] nums1, int[] nums2) {\n        long currSum = 0, sum1 = 0, sum2 = 0;\n        int i = 0;\n        int j = 0;\n  
```\nclass Solution {\n    public int maxSum(int[] nums1, int[] nums2) {\n        long currSum = 0, sum1 = 0, sum2 = 0;\n        int i = 0;\n        int j = 0;\n        while(i < nums1.length && j < nums2.length){\n            if(nums1[i] == nums2[j]) {\n                currSum += Math.max(sum1, sum2) + nums2[j];\n                sum1 = 0;\n                sum2 = 0;\n                i++;\n                j++;\n            }\n            else if(nums1[i] < nums2[j]){\n                sum1 += nums1[i++];\n            } else {\n                sum2 += nums2[j++];\n            }\n        }\n       \n        while(i < nums1.length){\n            sum1 += nums1[i++];\n        }\n        while(j < nums2.length){\n            sum2 += nums2[j++];\n        }\n        return (int)((currSum + Math.max(sum1, sum2)) % 1000000007);\n    }\n}\n```
['Two Pointers', 'Java']