Python Elegant & Short | RegEx | Two lines
\timport re\n\tfrom fractions import Fraction\n\n\n\tclass Solution:\n\t\t"""\n\t\tTime:   O(n)\n\t\tMemory: O(n)\n\t\t"""\n\n\t\tFRACTION_PATTERN = r\'([+-]?[^
\timport re\n\tfrom fractions import Fraction\n\n\n\tclass Solution:\n\t\t"""\n\t\tTime:   O(n)\n\t\tMemory: O(n)\n\t\t"""\n\n\t\tFRACTION_PATTERN = r\'([+-]?[^+-]+)\'\n\t\t\n\t\t# First solution\n\t\tdef fractionAddition(self, expression: str) -> str:\n\t\t\tresult_fraction = Fraction(0)\n\n\t\t\tfor exp in re.findall(self.FRACTION_PATTERN, expression):\n\t\t\t\tn, d = map(int, exp.split(\'/\'))\n\t\t\t\tresult_fraction += Fraction(n, d)\n\n\t\t\treturn f\'{result_fraction.numerator}/{result_fraction.denominator}\'\n\n\t\t# Second solution\n\t\tdef fractionAddition(self, expression: str) -> str:\n\t\t\tresult_fraction = sum(\n\t\t\t\t(Fraction(*map(int, exp.split(\'/\'))) for exp in re.findall(self.FRACTION_PATTERN, expression)),\n\t\t\t\tFraction(0)\n\t\t\t)\n\t\t\treturn f\'{result_fraction.numerator}/{result_fraction.denominator}\'\n
['Python', 'Python3']