Skip to content

Commit

Permalink
go quicksort
Browse files Browse the repository at this point in the history
  • Loading branch information
Azureki committed May 12, 2019
1 parent 0dc94b0 commit 052824a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 912. Sort an Array/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package leetcode

func sortArray(nums []int) []int {
if len(nums) == 0 {
return []int{}
}
temp := nums[0]
lo, hi := 0, len(nums)-1
for lo < hi {
for lo < hi && nums[hi] >= temp {
hi--
}
for lo < hi && nums[lo] <= temp {
lo++
}
nums[lo], nums[hi] = nums[hi], nums[lo]
}
nums[0], nums[hi] = nums[hi], nums[0]
sortArray(nums[0:lo])
sortArray(nums[lo+1 : len(nums)])
return nums
}

0 comments on commit 052824a

Please sign in to comment.