题目描述
老阅读题了= =,第一遍看题的时候一脸懵逼 但其实代码就6行(嘿嘿)
思路 && 代码
class Solution { public int [ ] [ ] reconstructQueue ( int [ ] [ ] people) { Arrays . sort ( people, ( p1, p2) -> ( ( p1[ 0 ] == p2[ 0 ] ? p1[ 1 ] - p2[ 1 ] : p2[ 0 ] - p1[ 0 ] ) ) ) ; List < int [ ] > ans = new ArrayList < > ( ) ; for ( int [ ] temp : people) { ans. add ( temp[ 1 ] , temp) ; } return ans. toArray ( new int [ ans. size ( ) ] [ ] ) ; }
}
class Solution { public int [ ] [ ] reconstructQueue ( int [ ] [ ] people) { Arrays . sort ( people, ( p1, p2) -> ( ( p1[ 0 ] == p2[ 0 ] ? p1[ 1 ] - p2[ 1 ] : p2[ 0 ] - p1[ 0 ] ) ) ) ; List < int [ ] > ans = new ArrayList < > ( ) ; for ( int [ ] temp : people) { ans. add ( temp[ 1 ] , temp) ; } return ans. toArray ( new int [ ans. size ( ) ] [ ] ) ; }
}
二刷
class Solution { public int [ ] [ ] reconstructQueue ( int [ ] [ ] people) { Arrays . sort ( people, ( int [ ] a, int [ ] b) -> ( a[ 0 ] == b[ 0 ] ? a[ 1 ] - b[ 1 ] : b[ 0 ] - a[ 0 ] ) ) ; List < int [ ] > ans = new ArrayList < > ( ) ; for ( int [ ] temp : people) { ans. add ( temp[ 1 ] , temp) ; } return ans. toArray ( new int [ ans. size ( ) ] [ ] ) ; }
}