Ai
2 Star 1 Fork 1

望曦开源团队/Python案例合集

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
CountSort.py 514 Bytes
一键复制 编辑 原始数据 按行查看 历史
NineSenz-九练 提交于 2023-05-11 00:00 +08:00 . 计数排序
def countSort(arr):
output = [0 for i in range(256)]
count = [0 for i in range(256)]
ans = ["" for _ in arr]
for i in arr:
count[ord(i)] += 1
for i in range(256):
count[i] += count[i-1]
for i in range(len(arr)):
output[count[ord(arr[i])]-1] = arr[i]
count[ord(arr[i])] -= 1
for i in range(len(arr)):
ans[i] = output[i]
return ans
arr = "wwwwangxioscom"
ans = countSort(arr)
print ( "字符数组排序 %s" %("".join(ans)) )
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wangxios/workspace_Python.git
git@gitee.com:wangxios/workspace_Python.git
wangxios
workspace_Python
Python案例合集
master

搜索帮助