快速排序
func QuickSort(sort []int) []int {
if len(sort) <= 1 {
return sort
}
low := make([]int, 0, 0)
mid := make([]int, 0, 0)
high := make([]int, 0, 0)
tag := sort[0]
mid = append(mid, tag)
for i := 1; i < len(sort); i++ {
if sort[i] < tag {
low = append(low, sort[i])
} else if sort[i] > tag {
high = append(high, sort[i])
} else {
mid = append(mid, sort[i])
}
}
low, high = QuickSort(low), QuickSort(high)
return append(append(low, mid...), high...)
}
反转字符串包含数字中英文
func ReveverString(strs string) string {
s := []rune(strs)
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
s[i], s[j] = s[j], s[i]
}
return string(s)
}
反转链表
type ListNode struct {
Val int
Next *ListNode
}
func ReverseList(head *ListNode) *ListNode {
cur := head
var pre *ListNode = nil
for cur != nil {
pre, cur, cur.Next = cur, cur.Next, pre
}
return pre
}
标签:pre,high,常用,ListNode,cur,sort,Golang,算法,append
From: https://www.cnblogs.com/9men/p/16735906.html