Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- boolean areSimilar(int[] a, int[] b) {
- if(Arrays.equals(a, b)) return true;
- int mismatch1 = -1;
- int mismatch2 = -1;
- int temp = 0;
- for(int i = 0; i < a.length; i++){
- if(a[i] != b[i]) {
- if(mismatch1 == -1) {
- mismatch1 = i;
- continue;
- }
- else{
- mismatch2 = i;
- break;
- }
- }
- }
- temp = a[mismatch1];
- a[mismatch1] = a[mismatch2];
- a[mismatch2] = temp;
- return Arrays.equals(a, b);
- }
Add Comment
Please, Sign In to add comment