数组 Vector
对二维数组的每一行进行倒序遍历, 取非, 构造成新的二维数组即可.
code:1
2
3
4
5
6
7
8
9
10
11
12
13
14class Solution {
public:
vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) {
vector<vector<int>> ans;
for (auto i:A) {
vector<int> line;
for (auto j = i.rbegin(); j != i.rend(); ++j) {
line.push_back(!(*j));
}
ans.push_back(line);
}
return ans;
}
};