mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:55:35 +08:00
update book code
This commit is contained in:
23
eBook/exercises/chapter_7/uniq.go
Executable file
23
eBook/exercises/chapter_7/uniq.go
Executable file
@@ -0,0 +1,23 @@
|
||||
// Q29_uniq.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var arr []byte = []byte{'a','b','a','a','a','c','d','e','f','g'}
|
||||
|
||||
func main() {
|
||||
arru := make([]byte,len(arr)) // this will contain the unique items
|
||||
ixu := 0 // index in arru
|
||||
tmp := byte(0)
|
||||
for _, val := range arr {
|
||||
if val!=tmp {
|
||||
arru[ixu] = val
|
||||
fmt.Printf("%c ", arru[ixu])
|
||||
ixu++
|
||||
}
|
||||
tmp = val
|
||||
}
|
||||
// fmt.Println(arru)
|
||||
}
|
Reference in New Issue
Block a user