04. Swap the array elements
My Approach
Time and Auxiliary Space Complexity
Code (C++)
class Solution {
public:
void swapElements(int arr[], int n) {
for (int i = 0; i < n - 2; ++i) {
arr[i] = arr[i] ^ arr[i + 2];
arr[i + 2] = arr[i] ^ arr[i + 2];
arr[i] = arr[i] ^ arr[i + 2];
}
}
};Contribution and Support
Last updated