java
\nclass Solution {\n    public int maxSum(int[] nums1, int[] nums2) {\n        int i=0;\n        int j=0;\n        long ans1 = 0;\n        long ans2 = 0;\n     
```\nclass Solution {\n    public int maxSum(int[] nums1, int[] nums2) {\n        int i=0;\n        int j=0;\n        long ans1 = 0;\n        long ans2 = 0;\n        long ans = 0;\n        while(i!=nums1.length&&j!=nums2.length){\n            if(nums1[i]>nums2[j])\n              ans2 += nums2[j++];\n            else if(nums1[i]<nums2[j])\n                ans1 += nums1[i++];\n            else{\n                ans+=Math.max(ans1,ans2)+nums1[i];\n                i++;\n                j++;\n                ans1=0;\n                ans2=0;\n            }\n        }\n        while(i!=nums1.length){\n            ans1 += nums1[i];\n            i++;\n        }\n        while(j!=nums2.length){\n            ans2 += nums2[j];\n            j++;\n        }\n        ans += Math.max(ans1,ans2);\n        return (int)(ans%((int)Math.pow(10,9)+7));\n    }\n}\n```
['Two Pointers']