Skip to content

Commit

Permalink
Update 04.Array-Shell-Sort.md
Browse files Browse the repository at this point in the history
  • Loading branch information
itcharge committed Nov 25, 2021
1 parent 80206c1 commit 08cc78c
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions Contents/01.Array/02.Array-Sort/04.Array-Shell-Sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,23 @@
## 5. 代码实现

```Python
def shellSort(arr):
size = len(arr)
gap = size // 2

while gap > 0:
for i in range(gap, size):
temp = arr[i]
j = i
while j >= gap and arr[j - gap] > temp:
arr[j] = arr[j - gap]
j -= gap
arr[j] = temp
gap = gap // 2
return arr
class Solution:
def shellSort(self, arr):
size = len(arr)
gap = size // 2

while gap > 0:
for i in range(gap, size):
temp = arr[i]
j = i
while j >= gap and arr[j - gap] > temp:
arr[j] = arr[j - gap]
j -= gap
arr[j] = temp
gap = gap // 2
return arr

def sortArray(self, nums: List[int]) -> List[int]:
return self.shellSort(nums)
```

0 comments on commit 08cc78c

Please sign in to comment.