Skip to content

[解题分享] 60 #67

@bosens-China

Description

@bosens-China

您的答案 (Your Solution)

import copy

def bubble_sort(numbers: list[int]) -> list[int]:
    """
    使用冒泡排序算法对一个数字列表进行升序排序。
    :param numbers: 一个数字列表
    :return: 排序后的新列表(为了不修改原始列表)
    """
    # https://www.runoob.com/w3cnote/bubble-sort.html 参考这个实现
    result:list[int] = copy.deepcopy(numbers)
    length = len(result)
    for i in range(0, length):
        for j in range(length - 1 - i):
            if result[j] > result[j + 1]:
                result[j], result[j + 1] = result[j + 1], result[j]
    
    return result

解题思路 (Thought Process)

No response

其他信息 (Additional context)

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions