Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c5d058a

Browse files
Merge pull request #1 from LokiSharp/patch-2
Add Python
2 parents d29ac91 + 4b2c21f commit c5d058a

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

‎8.countingSort.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,23 @@ function countingSort(arr, maxValue) {
3232

3333
return arr;
3434
}
35-
```
35+
```
36+
## 3. JavaScript 代码实现
37+
38+
```python
39+
def countingSort(arr, maxValue):
40+
bucketLen = maxValue+1
41+
bucket = [0]*bucketLen
42+
sortedIndex =0
43+
arrLen = len(arr)
44+
for i in range(arrLen):
45+
if not bucket[arr[i]]:
46+
bucket[arr[i]]=0
47+
bucket[arr[i]]+=1
48+
for j in range(bucketLen):
49+
while bucket[j]>0:
50+
arr[sortedIndex] = j
51+
sortedIndex+=1
52+
bucket[j]-=1
53+
return arr
54+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /