当前位置:网站首页>Leetcode skimming ---832
Leetcode skimming ---832
2022-07-03 10:35:00 【Long time no see 0327】
subject : Given a n x n The binary matrix of image , Flip the image horizontally first , Then invert the image and return the result . Flip the picture horizontally is to flip every line of the picture , Reverse order . for example , Flip horizontal [1,1,0] The result is [0,1,1]. Reverse picture means... In picture 0 All by 1 Replace , 1 All by 0 Replace . for example , reverse [0,1,1] The result is [1,0,0].
Input :image = [[1,1,0],[1,0,1],[0,0,0]]
Output :[[1,0,0],[0,1,0],[1,1,1]]
Method 1 : Simulation optimization + Double pointer
class Solution {
public:
vector<vector<int>> flipAndInvertImage(vector<vector<int>>& image) {
int n = image.size();
for (int i = 0; i < n; i++) {
int left = 0, right = n - 1;
while (left < right) {
if (image[i][left] == image[i][right]) {
image[i][left] ^= 1;
image[i][right] ^= 1;
}
left++;
right--;
}
if (left == right) {
image[i][left] ^= 1;
}
}
return image;
}
};
Complexity analysis
Time complexity :O(n^2)
Spatial complexity :O(1)
边栏推荐
- An open source OA office automation system
- 八、MySQL之事务控制语言
- ECMAScript--》 ES6语法规范 ## Day1
- [graduation season] the picture is rich, and frugality is easy; Never forget chaos and danger in peace.
- Leetcode刷题---44
- Leetcode刷题---704
- Advantageous distinctive domain adaptation reading notes (detailed)
- What can I do to exit the current operation and confirm it twice?
- Out of the box high color background system
- 3.3 Monte Carlo Methods: case study: Blackjack of Policy Improvement of on- & off-policy Evaluation
猜你喜欢
Ut2016 learning notes
Ut2017 learning notes
波士顿房价预测(TensorFlow2.9实践)
Simple real-time gesture recognition based on OpenCV (including code)
Ut2012 learning notes
Leetcode - the k-th element in 703 data flow (design priority queue)
Introduction to deep learning linear algebra (pytorch)
A super cool background permission management system
六、MySQL之数据定义语言(一)
Policy gradient Method of Deep Reinforcement learning (Part One)
随机推荐
Ind FXL first week
侯捷——STL源码剖析 笔记
Pytorch ADDA code learning notes
The imitation of jd.com e-commerce project is coming
Ut2012 learning notes
What did I read in order to understand the to do list
权重衰退(PyTorch)
Hands on deep learning pytorch version exercise solution -- implementation of 3-2 linear regression from scratch
Tensorflow - tensorflow Foundation
多层感知机(PyTorch)
Leetcode刷题---832
神经网络入门之模型选择(PyTorch)
安装yolov3(Anaconda)
Leetcode刷题---1385
[graduation season] the picture is rich, and frugality is easy; Never forget chaos and danger in peace.
Ut2014 supplementary learning notes
Powshell's set location: unable to find a solution to the problem of accepting actual parameters
Leetcode - 705 design hash set (Design)
Leetcode刷题---704
2018 y7000 upgrade hard disk + migrate and upgrade black apple