代码/思路
class Solution {
public :
vector< int > sortArray ( vector< int > & nums) {
sort ( nums. begin ( ) , nums. end ( ) ) ;
return nums;
}
} ;
代码/思路
class Solution {
public :
void merge ( vector< int > & nums1, int m, vector< int > & nums2, int n) {
for ( int i = 0 ; i < n; i++ )
{
nums1[ m + i] = nums2[ i] ;
}
sort ( nums1. begin ( ) , nums1. end ( ) ) ;
}
} ;
代码/思路
class Solution {
public :
bool isBoomerang ( vector< vector< int >> & points) {
sort ( points. begin ( ) , points. end ( ) ,
[ & ] ( const vector< int > & a, const vector< int > & b) {
if ( a[ 0 ] == b[ 0 ] )
{
return a[ 1 ] < b[ 1 ] ;
}
return a[ 0 ] < b[ 0 ] ;
} ) ;
points[ 1 ] [ 0 ] -= points[ 0 ] [ 0 ] ;
points[ 1 ] [ 1 ] -= points[ 0 ] [ 1 ] ;
points[ 2 ] [ 0 ] -= points[ 0 ] [ 0 ] ;
points[ 2 ] [ 1 ] -= points[ 0 ] [ 1 ] ;
int cx = points[ 1 ] [ 0 ] * points[ 2 ] [ 1 ] - points[ 1 ] [ 1 ] * points[ 2 ] [ 0 ] ;
return cx != 0 ;
}
} ;
代码/思路
class Solution {
public :
bool checkStraightLine ( vector< vector< int >> & coordinates) {
sort ( coordinates. begin ( ) , coordinates. end ( ) ,
[ & ] ( const vector< int > & a, const vector< int > & b) {
if ( a[ 0 ] == b[ 0 ] )
{
return a[ 1 ] < b[ 1 ] ;
}
return a[ 0 ] < b[ 0 ] ;
} ) ;
for ( int i = 1 ; i < coordinates. size ( ) ; i++ )
{
coordinates[ i] [ 0 ] -= coordinates[ 0 ] [ 0 ] ;
coordinates[ i] [ 1 ] -= coordinates[ 0 ] [ 1 ] ;
}
for ( int i = 2 ; i < coordinates. size ( ) ; i++ )
{
if ( coordinates[ i] [ 0 ] * coordinates[ i - 1 ] [ 1 ] != coordinates[ i] [ 1 ] * coordinates[ i - 1 ] [ 0 ] )
{
return false ;
}
}
return true ;
}
} ;