Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 69f0a94

Browse files
committed
972 wrong answer
1 parent 31567b4 commit 69f0a94

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

Algorithms/0972.equal-rational-numbers/equal-rational-numbers.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func isRationalEqual(S string, T string) bool {
2525
func parse(s string) (string, string, string) {
2626
dot := strings.Index(s, ".")
2727
if dot == -1 {
28-
return s, "", ""
28+
return s, "0", ""
2929
}
3030

3131
integer, fraction := s[:dot], s[dot+1:]
@@ -38,6 +38,14 @@ func parse(s string) (string, string, string) {
3838
nonRepeat := fraction[:l]
3939
repeat := fraction[l+1 : len(fraction)-1]
4040

41+
if repeat == "0" {
42+
repeat = ""
43+
}
44+
45+
if repeat == "" && nonRepeat == "" {
46+
nonRepeat = "0"
47+
}
48+
4149
return integer, nonRepeat, repeat
4250
}
4351

@@ -62,10 +70,6 @@ func simplify(nonRepeat, repeat string) (string, string) {
6270
}
6371
}
6472

65-
if repeat == "0" {
66-
repeat = ""
67-
}
68-
6973
return nonRepeat, repeat
7074
}
7175

Algorithms/0972.equal-rational-numbers/equal-rational-numbers_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ var tcs = []struct {
1414
}{
1515

1616
{
17-
"1.0",
18-
"1",
17+
"0",
18+
"0.",
1919
true,
2020
},
2121

@@ -25,6 +25,12 @@ var tcs = []struct {
2525
true,
2626
},
2727

28+
{
29+
"1.0",
30+
"1",
31+
true,
32+
},
33+
2834
{
2935
"0.(52)",
3036
"0.5(25)",

0 commit comments

Comments
 (0)