Minimum Add to Make Parentheses Valid Solutions in GoNumber 921Difficulty MediumAcceptance 73.8%Link LeetCodeOther languages C++SolutionsGo solution by halfrost/LeetCode-Gopackage leetcode func minAddToMakeValid(S string) int { if len(S) == 0 { return 0 } stack := make([]rune, 0) for _, v := range S { if v == '(' { stack = append(stack, v) } else if (v == ')') && len(stack) > 0 && stack[len(stack)-1] == '(' { stack = stack[:len(stack)-1] } else { stack = append(stack, v) } } return len(stack)}package leetcode func minAddToMakeValid(S string) int { if len(S) == 0 { return 0 } stack := make([]rune, 0) for _, v := range S { if v == '(' { stack = append(stack, v) } else if (v == ')') && len(stack) > 0 && stack[len(stack)-1] == '(' { stack = stack[:len(stack)-1] } else { stack = append(stack, v) } } return len(stack) }