res := make([]int, len(nums))
for i := 0; i < len(nums); i++ {
if i == 0 {
prefix_val := 1
} else {
prefix_val := prefix[i-1]
}
if i == len(nums) - 1 {
postfix_val := 1
} else {
postfix_val := postfix[i+1]
}
res[i] = prefix_val * postfix_val
}
Error:
Line 25: Char 13: declared and not used: prefix_val (solution.go)
Line 27: Char 13: declared and not used: prefix_val (solution.go)
Line 30: Char 13: declared and not used: postfix_val (solution.go)
Line 32: Char 13: declared and not used: postfix_val (solution.go)
Line 34: Char 18: undefined: prefix_val (solution.go)
Line 34: Char 31: undefined: postfix_val (solution.go)
Why does the compiler say I have not used prefix_val and postfix_val when you can clearly see it being used in the last line? It also says that both the before mentioned variables are undefined which are clearly defined above.