1、题目描述
2、题目分析
使用C++的迭代器
3、代码
1 vector> flipAndInvertImage(vector >& A) { 2 for( vector >::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 }