调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
中等
相关标签
相关企业
提示

给定两个整数,分别表示分数的分子 numerator 和分母 denominator,以 字符串形式返回小数

如果小数部分为循环小数,则将循环的部分括在括号内。

如果存在多个答案,只需返回 任意一个

对于所有给定的输入,保证 答案字符串的长度小于 104

 

示例 1:

输入:numerator = 1, denominator = 2
输出:"0.5"

示例 2:

输入:numerator = 2, denominator = 1
输出:"2"

示例 3:

输入:numerator = 4, denominator = 333
输出:"0.(012)"

 

提示:

  • -231 <= numerator, denominator <= 231 - 1
  • denominator != 0
通过次数
74.3K
提交次数
220.9K
通过率
33.6%


相关企业

提示 1
No scary math, just apply elementary math knowledge. Still remember how to perform a long division?

提示 2
Try a long division on 4/9, the repeating part is obvious. Now try 4/333. Do you see a pattern?

提示 3
Notice that once the remainder starts repeating, so does the divided result.

提示 4
Be wary of edge cases! List out as many test cases as you can think of and test your code thoroughly.

评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
运行和提交代码需要登录
numerator =
1
denominator =
2
Source