添加了python版本代码

为数据结构和算法文件夹下的代码增加了python语言版本
This commit is contained in:
goodyong
2021-07-05 22:25:41 +08:00
parent a503e97f11
commit 4e661354d4
16 changed files with 1088 additions and 83 deletions

View File

@@ -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
```
**简单选择排序时间复杂度分析**