题目链接:https://leetcode.com/problems/flipping-an-image/description/
题目解析:vector的反转可以很方便使用reverse,然后将0 1对调即可。
代码如下:8ms Accepted
class Solution {
public:
vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) {
vector<vector<int>>ans;
for (auto v : A)
{
reverse(v.begin(), v.end());
for (std::vector<int>::iterator it=v.begin(); it!=v.end(); ++it)
if (*it == 0)
*it = 1;
else
*it = 0;
ans.push_back(v);
}
return ans;
}
};