We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Sorting
- Counting Sort 1
- Discussions
Counting Sort 1
Counting Sort 1
+ 0 comments Python 3
def countingSort(arr): index_sort = [0] * 100 for i in arr: index_sort[i] += 1 return index_sort
+ 0 comments python solution
length = len(arr) result = [0] * length for i in arr: result[i] = result[i] + 1 return result[:100]
+ 0 comments JAVA
// Write your code here List<Integer> res = new ArrayList<>(); for(int i=0; i<100; i++) { res.add(i, Collections.frequency(arr, i)); } return res;
+ 0 comments Here is my c++ solution, you can watch the explanation here :
vector<int> countingSort(vector<int> arr) { vector<int> count(100, 0); for(int i = 0; i < arr.size(); i++) count[arr[i]]++; return count; }
+ 0 comments Python 3:
def countingSort(arr): index_sort = [0] * 100 for i in arr: index_sort[i] += 1 return index_sort
Load more conversations
Sort 440 Discussions, By:
Please Login in order to post a comment