about using the Arrays.sort () method in Java tle

Source: Internet
Author: User

Recently has been practicing with the Java writing problem (link), today did not want to find a very simple two-part problem, I started is directly open int[] array call Arrays.sort () to sort, did not think of Tle, originally because the JDK for int[] sort is the use of fast sorting, The relevant call source code in JDK is as follows

1      Public Static void sort (int[] a) {2         null, 0, 0); 3     }
View Code

And the test data just has the anti-fast row of data, so the card.

The solution is also a lot, it is relatively simple to use the wrapper class integer to call ARRAYS.SORT,JDK implementation is based on Timsort, can be seen from the following source code related calls.

1      Public Static void sort (object[] a) {2         if (legacymergesort.userrequested) 3             Legacymergesort (a); 4         Else 5             null, 0, 0); 6     }
View Code

Alternatively, you can use list, and then call Collections.sort ().

Of course, you can shuffle the array, and then call the sort, but in theory there is still a risk.

CF has a blog post can refer to: http://codeforces.com/blog/entry/7108

about using the Arrays.sort () method in Java tle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.