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

Commit 4c530c5

Browse files
committed
972 wrong answer
1 parent 69f0a94 commit 4c530c5

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,26 @@ func isRationalEqual(S string, T string) bool {
99
is, ns, rs := parse(S)
1010
it, nt, rt := parse(T)
1111

12-
if rs == "" && rt == "" {
13-
return is == it && ns == nt
14-
}
12+
// if rs == "" && rt == "" {
13+
// return is == it && ns == nt
14+
// }
1515

1616
ns, rs = simplify(ns, rs)
1717
nt, rt = simplify(nt, rt)
1818

1919
s, ns, rs := convert(is, ns, rs)
2020
t, nt, rt := convert(it, nt, rt)
2121

22-
return s == t && ns == nt && rs == rt
22+
return s == t &&
23+
ns == nt &&
24+
rs == rt
2325
}
2426

2527
func parse(s string) (string, string, string) {
28+
if strings.HasSuffix(s, ".") {
29+
s = s[:len(s)-1]
30+
}
31+
2632
dot := strings.Index(s, ".")
2733
if dot == -1 {
2834
return s, "0", ""
@@ -78,6 +84,7 @@ func convert(integer, nonRepeat, repeat string) (int, string, string) {
7884
if nonRepeat == "" && repeat == "9" {
7985
i++
8086
repeat = ""
87+
nonRepeat = "0"
8188
}
8289
return i, nonRepeat, repeat
8390
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ var tcs = []struct {
1313
ans bool
1414
}{
1515

16+
{
17+
"1.9(0)",
18+
"1.8(9)",
19+
true,
20+
},
21+
22+
{
23+
"0.9(9)",
24+
"1.",
25+
true,
26+
},
27+
1628
{
1729
"0",
1830
"0.",

0 commit comments

Comments
 (0)