翻转镜像

class Solution {
public:
	vector> flipAndInvertImage(vector>& A) {
		size_t m = A.size();
		size_t n = A[0].size();

		int half = n / 2, temp = 0;

		for (int i = 0; i < m; i++) {
			if (n % 2==0) {
				for (int j = 0; j < half; j++) {
					temp = A[i][j];
					A[i][j] = 1 - A[i][n - 1 - j];
					A[i][n - 1 - j] = 1 - temp;
				}
			}
			else {
				cout << half << endl;
				for (int j = 0; j < half; j++) {
					temp = A[i][j];
					A[i][j] = 1 - A[i][n - 1 - j];
					A[i][n - 1 - j] = 1 - temp;
				}
				A[i][half] = 1 - A[i][half];
			}
		}
		return A;
	}
};

 

你可能感兴趣的:(LeetCode)