leetcode 832.翻转图像
1.题目要求:
2.题目代码:
class Solution {
public:
//水平反转函数
void replace_photo(vector<int>& array){
for(int i = 0;i < array.size();i++){
if(array[i] == 1){
array[i] = 0;
}else{
array[i] = 1;
}
}
}
vector<vector<int>> flipAndInvertImage(vector<vector<int>>& image) {
//先进行水平翻转
for(int i = 0;i < image.size();i++){
reverse(image[i].begin(),image[i].end());
}
//再进行水品反转
for(int i = 0;i < image.size();i++){
replace_photo(image[i]);
}
return image;
}
};