C# Solution for Fraction Addition and Subtraction Problem
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem involves adding and subtracting fractions, which can be simplified by first
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem involves adding and subtracting fractions, which can be simplified by first finding a common denominator for all the fractions and then summing the numerators accordingly. This approach allows us to handle all the fractions simultaneously rather than incrementally updating the result.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1.\tParse the Expression:\n\t\u2022\tIterate through the string to identify and extract the numerators and denominators of each fraction. Store these values separately in two lists: numerators and denominators.\n2.\tFind the Least Common Multiple (LCM):\n\t\u2022\tTo sum fractions with different denominators, first find the LCM of all the denominators. This LCM will serve as a common denominator for the final addition.\n3.\tAdjust Numerators to the Common Denominator:\n\t\u2022\tFor each fraction, adjust its numerator so that its denominator matches the common denominator. This is done by multiplying the numerator by the necessary factor (i.e., LCM divided by the fraction\u2019s denominator).\n4.\tSum the Numerators:\n\t\u2022\tSum up all the adjusted numerators, which gives the total numerator for the final fraction with the common denominator.\n5.\tSimplify the Result:\n\t\u2022\tSimplify the final fraction by dividing both the numerator and the denominator by their Greatest Common Divisor (GCD).\n6.\tReturn the Result:\n\t\u2022\tReturn the result as a string in the format numerator/denominator.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\u2022\tO(n): The time complexity is linear relative to the length of the input string n. Parsing the expression, finding the LCM, adjusting numerators, and summing them are all done in a single pass through the input.\n\u2022\tO(m \\cdot log(D)): The complexity for finding the GCD and LCM involves logarithmic operations relative to the denominators. Here, m is the number of fractions, and D represents the magnitude of the denominators.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\u2022\tO(m): The space complexity is linear relative to the number of fractions m. The space is primarily used to store the lists of numerators and denominators.\n\u2022\tO(1) for other auxiliary variables, as the LCM and GCD calculations do not require additional space proportional to the input size.\n\n# Code\n```csharp []\npublic class Solution {\n    public string FractionAddition(string expression) {\n        List<int> numerators = new List<int>();\n        List<int> denominators = new List<int>();\n\n        int i = 0;\n        while (i < expression.Length) {\n            int sign = 1;\n            if (expression[i] == \'-\' || expression[i] == \'+\') {\n                sign = expression[i] == \'-\' ? -1 : 1;\n                i++;\n            }\n\n            int num = 0;\n            while (i < expression.Length && char.IsDigit(expression[i])) {\n                num = num * 10 + (expression[i] - \'0\');\n                i++;\n            }\n\n            i++; // skip the \'/\'\n\n            int denom = 0;\n            while (i < expression.Length && char.IsDigit(expression[i])) {\n                denom = denom * 10 + (expression[i] - \'0\');\n                i++;\n            }\n\n            numerators.Add(sign * num);\n            denominators.Add(denom);\n        }\n\n        int commonDenominator = 1;\n        foreach (int denom in denominators) {\n            commonDenominator = lcm(commonDenominator, denom);\n        }\n\n        int totalNumerator = 0;\n        for (int j = 0; j < numerators.Count; j++) {\n            totalNumerator += numerators[j] * (commonDenominator / denominators[j]);\n        }\n\n        int gcdValue = gcd(Math.Abs(totalNumerator), commonDenominator);\n        return (totalNumerator / gcdValue) + "/" + (commonDenominator / gcdValue);\n    }\n\n    private int gcd(int a, int b) {\n        return b == 0 ? a : gcd(b, a % b);\n    }\n\n    private int lcm(int a, int b) {\n        return a / gcd(a, b) * b;\n    }\n}\n```
['C#']