《Hello 算法》:动画图解、一键运行的数据结构与算法教程。支持 Python, Java, C++, C, C#, JS, Go, Swift, Rust, Ruby, Kotlin, TS, Dart 代码。简体版和繁体版同步更新,English version ongoing
95.04k
stars
12.07k
forks
source link
C++ // Counting Sort // "Handle empty array" #1460
Closed
JeninSutradhar closed 1 month ago
Counting Sort C++ C++ implementation is mostly correct but it does not handle the case where the input array is empty.
if (nums == null || nums.length == 0) { return; // handle empty array }
Add a check at the beginning to return immediately if the input array is empty or null.