We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给你一个整数 n,请你每隔三位添加点(即 "." 符号)作为千位分隔符,并将结果以字符串格式返回。
输入:n = 987 输出:"987"
输入:n = 1234 输出:"1.234"
输入:n = 123456789 输出:"123.456.789"
输入:n = 0 输出:"0"
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/thousand-separator 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered:
func thousandSeparator(n int) string { var ret strings.Builder s := strconv.Itoa(n) count := 0 for i := len(s)-1; i >= 0; i-- { if count % 3 == 0 && count != 0{ ret.WriteByte('.') } ret.WriteByte(s[i]) count++ } s = ret.String() var r strings.Builder for i := len(s)-1; i >= 0; i-- { r.WriteByte(s[i]) } return r.String() }
Sorry, something went wrong.
No branches or pull requests
给你一个整数 n,请你每隔三位添加点(即 "." 符号)作为千位分隔符,并将结果以字符串格式返回。
示例 1:
示例 2:
示例 3:
示例 4:
提示:
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/thousand-separator
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
The text was updated successfully, but these errors were encountered: