Make equal elements Array
1 2 3 4 5 6 7 8 9 10 11 12
| int Solution::solve(vector<int> &A, int B) { unordered_map<int, int> freq; for(int i = 0; i < A.size(); i++) { int sub = A[i] - B, add = A[i] + B, none = A[i]; freq[sub] += 1; freq[add] += 1; freq[none] += 1; if(freq[sub] != i + 1 and freq[add] != i + 1 and freq[none] != i + 1) return 0; } return 1; }
|