本文主要是介绍Golang | Leetcode Golang题解之第385题迷你语法分析器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
题解:
func deserialize(s string) *NestedInteger {index := 0var dfs func() *NestedIntegerdfs = func() *NestedInteger {ni := &NestedInteger{}if s[index] == '[' {index++for s[index] != ']' {ni.Add(*dfs())if s[index] == ',' {index++}}index++return ni}negative := s[index] == '-'if negative {index++}num := 0for ; index < len(s) && unicode.IsDigit(rune(s[index])); index++ {num = num*10 + int(s[index]-'0')}if negative {num = -num}ni.SetInteger(num)return ni}return dfs()
}
这篇关于Golang | Leetcode Golang题解之第385题迷你语法分析器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!