summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go33
1 files changed, 19 insertions, 14 deletions
diff --git a/main.go b/main.go
index 871d4ac..15fc67d 100644
--- a/main.go
+++ b/main.go
@@ -10,29 +10,32 @@ import (
"strings"
)
-type List map[int]int
+type List struct {
+ Map map[int]int
+ Homo int
+}
-func (l List) Insert(n int) {
- l[n]++
+func (l *List) Insert(n int) {
+ if l.Map[n]++; l.Map[n] > 1 {
+ l.Homo++
+ }
}
-func (l List) Delete(n int) {
- if l[n]--; l[n] <= 0 {
- delete(l, n)
+func (l *List) Delete(n int) {
+ if l.Map[n] > 1 {
+ l.Homo--
+ }
+ if l.Map[n]--; l.Map[n] <= 0 {
+ delete(l.Map, n)
}
}
func (l List) IsHomo() bool {
- for _, v := range l {
- if v > 1 {
- return true
- }
- }
- return false
+ return l.Homo > 0
}
func (l List) IsHetero() bool {
- return len(l) > 1
+ return len(l.Map) > 1
}
func Split(s string) (string, int) {
@@ -58,7 +61,9 @@ func (l List) Kind() string {
func Homo(r io.Reader, w io.Writer) {
scanner := bufio.NewScanner(r)
scanner.Scan() // eat # of cases
- l := make(List)
+ l := List{
+ Map: make(map[int]int),
+ }
for scanner.Scan() {
s, n := Split(scanner.Text())
switch s {