Runtime: 0 ms, faster than 100.00% of Go
// ( 40, ) 41, 0-9 48-57, A-Z 65-90, a-z 97-122\n// \u4ECE\u53F3\u8FB9\u5F00\u59CB\uFF0C\u9047\u5230\u6570\u5B57\u7F13\u5B58\u6570\u5B57\n// \u9047\u5230)\u6DFB
// ( 40, ) 41, 0-9 48-57, A-Z 65-90, a-z 97-122\n// \u4ECE\u53F3\u8FB9\u5F00\u59CB\uFF0C\u9047\u5230\u6570\u5B57\u7F13\u5B58\u6570\u5B57\n// \u9047\u5230)\u6DFB\u52A0\u500D\u6570\u5217\u8868\uFF0C\u540C\u65F6\u6E05\u7A7A\u7F13\u5B58\u6570\u5B57\n// \u9047\u5230(\u51CF\u5C11\u500D\u6570\u5217\u8868\n// \u9047\u5230\u5C0F\u5199\u7F13\u5B58\u5B57\u7B26\n// \u9047\u5230\u5927\u5199\u8F93\u51FA\u4E2A\u6570\uFF0C\u540C\u65F6\u6E05\u7A7A\u7F13\u5B58\u5B57\u7B26\u3001\u7F13\u5B58\u6570\u5B57\n```\nfunc countOfAtoms(formula string) string {\n\t// \u8F93\u51FAmaps\n\tvar maps = make(map[string]int)\n\t// \u500D\u6570\u5217\u8868\n\tvar multiple []int\n\t// \u7F13\u5B58\u5B57\u7B26\uFF0C\u7F13\u5B58\u6570\u5B57\n\tstr, count := "", ""\n\tfor i := len(formula) - 1; i >= 0; i-- {\n\t\tchar := formula[i]\n\t\tif char >= 48 && char <= 57 {\n\t\t\tcount = string(char) + count\n\t\t} else {\n\t\t\tif char == 41 {\n\t\t\t\tatoi, _ := strconv.Atoi(count)\n\t\t\t\tif len(multiple) > 0 {\n\t\t\t\t\tatoi = atoi * multiple[len(multiple)-1]\n\t\t\t\t}\n\t\t\t\tmultiple = append(multiple, atoi)\n\t\t\t\tcount = ""\n\t\t\t} else if char == 40 {\n\t\t\t\tmultiple = multiple[:len(multiple)-1]\n\t\t\t} else if char >= 97 && char <= 122 {\n\t\t\t\tstr = string(char) + str\n\t\t\t} else if char >= 65 && char <= 90 {\n\t\t\t\tstr = string(char) + str\n\t\t\t\tnums := 1\n\t\t\t\tif count == "" {\n\t\t\t\t\tcount = "1"\n\t\t\t\t}\n\t\t\t\tatoi, _ := strconv.Atoi(count)\n\t\t\t\tif len(multiple) > 0 {\n\t\t\t\t\tnums = multiple[len(multiple)-1] * atoi\n\t\t\t\t} else {\n\t\t\t\t\tnums = atoi\n\t\t\t\t}\n\t\t\t\tmaps[str] += nums\n\t\t\t\tstr = ""\n\t\t\t\tcount = ""\n\t\t\t}\n\t\t}\n\t}\n\t// \u6309\u5B57\u6BCD\u6392\u5E8F\u5E76\u8F93\u51FA\n\tresult := ""\n\tvar keys []string\n\tfor k := range maps {\n\t\tkeys = append(keys, k)\n\t}\n\tsort.Strings(keys)\n\tfor _, k := range keys {\n\t\tv := maps[k]\n\t\tresult += k\n\t\tif v != 1 {\n\t\t\tresult += strconv.Itoa(v)\n\t\t}\n\t}\n\treturn result\n}\n```
[]