当前位置:网站首页>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)
边栏推荐
- Label Semantic Aware Pre-training for Few-shot Text Classification
- C#项目-寝室管理系统(1)
- Preliminary knowledge of Neural Network Introduction (pytorch)
- Leetcode刷题---374
- 多层感知机(PyTorch)
- Hands on deep learning pytorch version exercise solution - 2.6 probability
- Are there any other high imitation projects
- 二分查找法
- 重写波士顿房价预测任务(使用飞桨paddlepaddle)
- 【SQL】一篇带你掌握SQL数据库的查询与修改相关操作
猜你喜欢

Leetcode - 705 design hash set (Design)

波士顿房价预测(TensorFlow2.9实践)

Matrix calculation of Neural Network Introduction (pytoch)

Stroke prediction: Bayesian

C#项目-寝室管理系统(1)

Timo background management system

Leetcode - 706 design hash mapping (Design)*

Realize an online examination system from zero

Knowledge map reasoning -- hybrid neural network and distributed representation reasoning

Leetcode-112: path sum
随机推荐
Boston house price forecast (tensorflow2.9 practice)
Several problems encountered in installing MySQL under MAC system
神经网络入门之矩阵计算(Pytorch)
八、MySQL之事务控制语言
Ut2013 learning notes
Hands on deep learning pytorch version exercise solution - 3.1 linear regression
Leetcode刷题---202
Ind FXL first week
A super cool background permission management system
Multi-Task Feature Learning for Knowledge Graph Enhanced Recommendation
ECMAScript--》 ES6语法规范 ## Day1
[LZY learning notes dive into deep learning] 3.5 image classification dataset fashion MNIST
侯捷——STL源码剖析 笔记
深度学习入门之线性回归(PyTorch)
CSDN, I'm coming!
Matrix calculation of Neural Network Introduction (pytoch)
Hands on deep learning pytorch version exercise answer - 2.2 preliminary knowledge / data preprocessing
Raspberry pie 4B installs yolov5 to achieve real-time target detection
Automatic derivation of introduction to deep learning (pytoch)
[LZY learning notes dive into deep learning] 3.1-3.3 principle and implementation of linear regression