File tree Expand file tree Collapse file tree 1 file changed +0
-36
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +0
-36
lines changed Original file line number Diff line number Diff line change 3
3
import java .util .ArrayList ;
4
4
import java .util .List ;
5
5
6
- /**
7
- * 592. Fraction Addition and Subtraction
8
- *
9
- * Given a string representing an expression of fraction addition and subtraction,
10
- * you need to return the calculation result in string format.
11
- * The final result should be irreducible fraction.
12
- * If your final result is an integer,
13
- * say 2, you need to change it to the format of fraction that has denominator 1.
14
- * So in this case, 2 should be converted to 2/1.
15
-
16
- Example 1:
17
- Input:"-1/2+1/2"
18
- Output: "0/1"
19
-
20
- Example 2:
21
- Input:"-1/2+1/2+1/3"
22
- Output: "1/3"
23
-
24
- Example 3:
25
- Input:"1/3-1/2"
26
- Output: "-1/6"
27
-
28
- Example 4:
29
- Input:"5/3+1/3"
30
- Output: "2/1"
31
-
32
- Note:
33
- The input string only contains '0' to '9', '/', '+' and '-'. So does the output.
34
- Each fraction (input and output) has format ±numerator/denominator.
35
- If the first input fraction or the output is positive, then '+' will be omitted.
36
- The input only contains valid irreducible fractions,
37
- where the numerator and denominator of each fraction will always be in the range [1,10].
38
- If the denominator is 1, it means this fraction is actually an integer in a fraction format defined above.
39
- The number of given fractions will be in the range [1,10].
40
- The numerator and denominator of the final result are guaranteed to be valid and in the range of 32-bit int.
41
- */
42
6
public class _592 {
43
7
44
8
public static class Solution1 {
You can’t perform that action at this time.
0 commit comments