利用stl中nth_element()找出第k小的数字
找出一个数组中第k小的数
一、朴素做法
sort() 时间复杂度:O(nlogn)
二、利用STL库函数nth_element()
时间复杂度:O(n)
用法:nth_element(a,a+k,a+n)
长度为n的数组a[]中找出第k小的数
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »
找出一个数组中第k小的数
一、朴素做法
sort() 时间复杂度:O(nlogn)
二、利用STL库函数nth_element()
时间复杂度:O(n)
用法:nth_element(a,a+k,a+n)
长度为n的数组a[]中找出第k小的数
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »