Skip to content

Commit

Permalink
Add Python
Browse files Browse the repository at this point in the history
  • Loading branch information
LokiSharp authored Jan 21, 2017
1 parent ae6fad9 commit 4b2c21f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion 8.countingSort.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,23 @@ function countingSort(arr, maxValue) {

return arr;
}
```
```
## 3. JavaScript 代码实现

```python
def countingSort(arr, maxValue):
bucketLen = maxValue+1
bucket = [0]*bucketLen
sortedIndex =0
arrLen = len(arr)
for i in range(arrLen):
if not bucket[arr[i]]:
bucket[arr[i]]=0
bucket[arr[i]]+=1
for j in range(bucketLen):
while bucket[j]>0:
arr[sortedIndex] = j
sortedIndex+=1
bucket[j]-=1
return arr
```

0 comments on commit 4b2c21f

Please sign in to comment.