标签:题意 异或 lan abs image vector c++ 模拟 and
对图片先水平翻转再反转图片
水平翻转:就是改为逆序,比如[1,0,0]->[0,0,1]
反转图片:0->1, 1->0
reverse()
^=1
,因为一个数和自己异或是0,0和1异或刚好是1=abs(1 - ?)
,利用绝对值abs
来实现转换class Solution {
public:
vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) {
for(auto &row: A) {
reverse(row.begin(), row.end());
}
for(auto &row: A) {
for(auto &ele: row) {
ele ^= 1;
}
}
return A;
}
};
标签:题意 异或 lan abs image vector c++ 模拟 and
原文地址:https://www.cnblogs.com/MartinLwx/p/14256967.html