Total 12 branches
Intuition\n Describe your first thoughts on how to solve this problem. \nUse the sum of number and count of zero in each array.\n\n### Approach\n Describe your 
### Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse the sum of number and count of zero in each array.\n\n### Approach\n<!-- Describe your approach to solving the problem. -->\nThere are total 12 branches, and we can combine some of them.\n\nAnd combine `1, 5, 9` branches with `max(S1+Z1, S2+Z2)` and skip all `X` which mean -1.\n\nCheck all positive branches and skip the negative branches.\n\nThis will give us concise code and more understading logic.\n\n**0 means there are zero, 1 means no zero in the array.**\n\n```  \n           0 0     S2+Z2                     1\n           1 0     S2 or X                   2\nS1 < S2\n           1 0     X                         3\n           1 1     X                         4\n\n           0 0     max(S1+Z1, S2+Z2)         5\n           1 0     X                         6\nS1 = S2\n           1 0     X                         7\n           1 1     S1                        8\n\n           0 0     S1+Z1                     9\n           1 0     X                         10\nS1 > S2\n           1 0     S1 or X                   11\n           1 1     X                         12\n```\n\n### 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  public long minSum(int[] nums1, int[] nums2) {\n    long[] sum = new long[2];\n    int[] zero = new int[2];\n    for (int num : nums1) {\n      if (num == 0) {\n        zero[0]++;\n      }\n      sum[0] += num;\n    }\n\n    for (int num : nums2) {\n      if (num == 0) {\n        zero[1]++;\n      }\n      sum[1] += num;\n    }\n\n    // both have zero, replace all zero with one in one array\n    if (zero[0] > 0 && zero[1] > 0) {\n      return Math.max(sum[0] + zero[0], sum[1] + zero[1]);\n    }\n\n    // one of array has zero\n    if (zero[0] > 0 && zero[1] == 0) {\n      if (sum[0] < sum[1] && sum[0] + zero[0] <= sum[1]) {\n        return sum[1];\n      }\n    }\n\n    if (zero[0] == 0 && zero[1] > 0) {\n      if (sum[0] > sum[1] && sum[0] >= sum[1] + zero[1]) {\n        return sum[0];\n      }\n    }\n\n    // no zero\n    if (zero[0] + zero[1] == 0) {\n      if (sum[0] == sum[1]) {\n        return sum[1];\n      }\n    }\n\n    return -1;\n  }\n}\n\n```
['Math', 'Counting', 'Java']