apuk
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
|
||||
initArr := []int{1,2,3,4,1,1,4,2,5}
|
||||
fmt.Println(initArr)
|
||||
|
||||
CountStrg := make(map[int]int)
|
||||
|
||||
for _,val := range initArr {
|
||||
// fmt.Printf("Key is %d and val is %d\n",key, val)
|
||||
if _,ok := CountStrg[val]; !ok {
|
||||
CountStrg[val] = 1
|
||||
continue
|
||||
}
|
||||
CountStrg[val]++
|
||||
}
|
||||
fmt.Println(CountStrg)
|
||||
fmt.Print("==========================\n")
|
||||
fmt.Println("Len of slice is: ",len(initArr)," and capacity is ",cap(initArr))
|
||||
initArr = append(initArr, 10)
|
||||
fmt.Print("==========================\n")
|
||||
fmt.Println("New len of slice is: ",len(initArr)," and new capacity is ",cap(initArr))
|
||||
}
|
||||
Reference in New Issue
Block a user