mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2025-08-07 15:52:12 +00:00
添加了python版本代码
为数据结构和算法文件夹下的代码增加了python语言版本
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
|
||||
**简单选择排序代码**
|
||||
|
||||
Java Code:
|
||||
|
||||
```java
|
||||
class Solution {
|
||||
public int[] sortArray(int[] nums) {
|
||||
@@ -46,6 +48,29 @@ class Solution {
|
||||
}
|
||||
```
|
||||
|
||||
Python Code:
|
||||
|
||||
```python
|
||||
from typing import List
|
||||
class Solution:
|
||||
def sortArray(self, nums: List[int])->List[int]:
|
||||
leng = len(nums)
|
||||
min = 0
|
||||
for i in range(0, leng):
|
||||
min = i
|
||||
# 遍历到最小值
|
||||
for j in range(i + 1, leng):
|
||||
if nums[min] > nums[j]:
|
||||
min = j
|
||||
if min != i:
|
||||
self.swap(nums, i, min)
|
||||
return nums
|
||||
|
||||
def swap(self, nums: List[int], i: int, j: int):
|
||||
temp = nums[i]
|
||||
nums[i] = nums[j]
|
||||
nums[j] = temp
|
||||
```
|
||||
|
||||
|
||||
**简单选择排序时间复杂度分析**
|
||||
|
Reference in New Issue
Block a user