题解 | #明明的随机数#使用快排
明明的随机数
https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0
package main
import(
"fmt"
)
func main(){
var t,num int
mp:=make(map[int]int)
res:=make([]int,0)
fmt.Scan(&t)
for i:=0;i<t;i++{
fmt.Scan(&num)
if mp[num]==0{
res=append(res,num)
mp[num]++
}
}
fastsort(res,0,len(res)-1)
for _,v:=range res{
fmt.Printf("%d\n",v)
}
}
func fastsort(a []int,l,r int){
if l >r{
return
}
left:=l
right:=r
for left<right{
for left<right&&a[right]>=a[l]{
right--
}
for left<right&&a[left]<=a[l]{
left++
}
a[left],a[right]=a[right],a[left]
}
a[l],a[left]=a[left],a[l]
fastsort(a,l,left-1)
fastsort(a,left+1,r)
}
import(
"fmt"
)
func main(){
var t,num int
mp:=make(map[int]int)
res:=make([]int,0)
fmt.Scan(&t)
for i:=0;i<t;i++{
fmt.Scan(&num)
if mp[num]==0{
res=append(res,num)
mp[num]++
}
}
fastsort(res,0,len(res)-1)
for _,v:=range res{
fmt.Printf("%d\n",v)
}
}
func fastsort(a []int,l,r int){
if l >r{
return
}
left:=l
right:=r
for left<right{
for left<right&&a[right]>=a[l]{
right--
}
for left<right&&a[left]<=a[l]{
left++
}
a[left],a[right]=a[right],a[left]
}
a[l],a[left]=a[left],a[l]
fastsort(a,l,left-1)
fastsort(a,left+1,r)
}