public void countSort(int[] nums){ int max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE; for(int num : nums){ max = Math.max(max, num); min = Math.min(min, num); } int[] countMap = new int[max-min+1]; for(int num : nums){ countMap[num-min]++; } int i = 0; int j = 0; while(i < nums.length && j < countMap.length){ if(countMap[j] > 0){ nums[i] = j+min; i++; countMap[j]--; } else { j++; } } }
PS:按顺序统计每个数出现次数。
上面是“java常见排序算法——计数排序(附代码示列)”的全面内容,想了解更多关于 后端开发 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_4261.html
workflows工作流
池塘边的大熊猫ComfyUI工作流
一棵白色心形流苏树comfyui工作流
一个红头发明亮眼睛的漂亮女人
坐落在白雪覆盖的广阔平原上2只可爱的雪豹
一个破旧的工厂,一个骷髅雕像
一条精致透明的朱红色水晶龙
一条色彩斑斓的超现实小孔雀鱼ComfyUI工作流
哈利波特魔法ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!