码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode题解之Flipping an Image

时间:2018-07-10 21:32:09      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:技术分享   color   style   src   nbsp   tco   pre   c++   div   

1、题目描述

技术分享图片

2、题目分析

使用C++的迭代器

3、代码

 1 vector<vector<int>> flipAndInvertImage(vector<vector<int>>& A) {
 2         for( vector<vector<int>>::iterator it = A.begin() ; it != A.end() ; it++ )
 3         {
 4             for(auto it_b = (*it).begin() ,it_e = (*it).end()-1 ; it_b <= it_e ; it_b++ ,it_e-- )
 5             {
 6                 int tmp = *it_b;
 7                 *it_b = *it_e;
 8                 *it_e = tmp;
 9                 
10                 if( it_b != it_e )
11                 {
12                    *it_b = ( *it_b == 1) ? 0 : 1;
13                    *it_e = ( *it_e == 1) ? 0 : 1;  
14                 }else{
15                     *it_b = ( *it_b == 1) ? 0:1 ;
16                 }
17             }
18         }
19         return A;
20         
21     }

 

LeetCode题解之Flipping an Image

标签:技术分享   color   style   src   nbsp   tco   pre   c++   div   

原文地址:https://www.cnblogs.com/wangxiaoyong/p/9291260.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!