aboutsummaryrefslogtreecommitdiff
path: root/challenge-326/deadmarshal/go/ch2.go
blob: c80834c5fb6f7d11a67a780d930dfce49cff29f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package main

import "fmt"

func decompressedList(arr []int) []int {
	res := []int{}
	for i := 0; i < len(arr); i += 2 {
		for j := 1; j <= arr[i]; j++ {
			res = append(res, arr[i+1])
		}
	}
	return res
}

func main() {
	fmt.Println(decompressedList([]int{1, 3, 2, 4}))
	fmt.Println(decompressedList([]int{1, 1, 2, 2}))
	fmt.Println(decompressedList([]int{3, 1, 3, 2}))
}