---
# System prepended metadata

title: 2449. Minimum Number of Operations to Make Arrays Similar
tags: [Leetcode, Hard, Greedy]

---

# 2449. Minimum Number of Operations to Make Arrays Similar
###### tags: `Leetcode` `Hard` `Greedy`
Link: https://leetcode.com/problems/minimum-number-of-operations-to-make-arrays-similar/description/
## 思路
思路参考[这里](https://leetcode.com/problems/minimum-number-of-operations-to-make-arrays-similar/solutions/2734189/c-python-sort-odds-and-evens/)
## Code
```java=
class Solution {
    public long makeSimilar(int[] A, int[] B) {
        List<Integer> A0 = new ArrayList<>();
        List<Integer> A1 = new ArrayList<>();
        List<Integer> B0 = new ArrayList<>();
        List<Integer> B1 = new ArrayList<>();
        for(int i=0; i<A.length; i++){
            if(A[i]%2==0) A0.add(A[i]);
            else A1.add(A[i]); 
        }
        for(int i=0; i<B.length; i++){
            if(B[i]%2==0) B0.add(B[i]);
            else B1.add(B[i]);
        }
        Collections.sort(A0);
        Collections.sort(A1);
        Collections.sort(B0);
        Collections.sort(B1);
        long ans = 0;
        for(int i=0; i<A0.size(); i++){
            ans += Math.abs(A0.get(i)-B0.get(i))/2;
        }
        for(int i=0; i<A1.size(); i++){
            ans += Math.abs(A1.get(i)-B1.get(i))/2;
        }
        return ans/2;
    }
}
```