THE
problem
solution
Code
class Solution {
public :
vector< int > FindNumsAppearOnce ( vector< int > & array) {
unordered_map< int , int > need;
vector< int > ans;
for ( int i = 0 ; i< array. size ( ) ; i++ ) {
need[ array[ i] ] ++ ;
}
for ( unordered_map< int , int > :: iterator it = need. begin ( ) ; it != need. end ( ) ; it++ ) {
if ( ( * it) . second < 2 ) ans. push_back ( ( * it) . first) ;
}
compare ( ans) ;
return ans;
}
void compare ( vector< int > & ans) {
if ( ans[ 0 ] > ans[ 1 ] ) {
int temp = ans[ 0 ] ;
ans[ 0 ] = ans[ 1 ] ;
ans[ 1 ] = temp;
}
}
} ;
Summary and reflection
The title of this question feels a bit problematic. It has been changed to be greater than or equal to 2, and the four 1s given by the test are considered duplicates.