Simple Approach beats 100% in Runtime
\n\n# Intuition\nWhen faced with the problem of adding or subtracting fractions, my first thought is to align all the fractions to a common denominator. This si
![image.png](https://assets.leetcode.com/users/images/958b4435-a830-4782-9b2c-f9ceb37c9bbf_1724407115.038779.png)\n\n# Intuition\nWhen faced with the problem of adding or subtracting fractions, my first thought is to align all the fractions to a common denominator. This simplifies the problem since fractions with the same denominator can be directly added or subtracted by operating on their numerators. The key challenge lies in determining this common denominator and then correctly adjusting each fraction accordingly.\n\n# Approach\nParse the Input: First, we need to parse the string to extract the numerators and denominators. This involves carefully handling signs and ensuring that we correctly parse multi-digit numbers.\n\nFind the Least Common Denominator (LCD): Once all fractions are parsed, the next step is to determine the least common denominator (LCD) of all the fractions. The LCD is the smallest common multiple of all denominators, which allows us to bring all fractions to a common base.\n\nAdjust Numerators: After finding the LCD, adjust each fraction\u2019s numerator so that all fractions have the same denominator (LCD). This is done by multiplying each numerator by the appropriate factor, derived from the ratio between the LCD and the original denominator.\n\nSum the Numerators: With all fractions aligned to the same denominator, their numerators can be directly summed up or subtracted based on their signs.\n\nSimplify the Result: Finally, simplify the resulting fraction by dividing both the numerator and denominator by their greatest common divisor (GCD). This step ensures that the fraction is in its simplest form.\n\nEdge Case: Handle special cases, such as when the result is zero, by returning "0/1".\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\n    int GCDFinder(int a, int b){\n        if(b == 0){\n            return abs(a);\n        }\n        return GCDFinder(b, a%b);\n    }\n\n    int LCMFinder(int a, int b){\n        int gcd = GCDFinder(a, b);\n        \n        return abs(a*b)/gcd;\n    }\n\n\npublic:\n    string fractionAddition(string expression) {\n        vector<int> nus, des;\n        int i = 0;\n        int n = expression.size();\n\n        while (i < n) {\n            int sign = 1;\n            if (expression[i] == \'+\' || expression[i] == \'-\') {\n                if (expression[i] == \'-\') sign = -1;\n                i++;\n            }\n\n            int numerator = 0;\n            while (i < n && isdigit(expression[i])) {\n                numerator = numerator * 10 + (expression[i] - \'0\');\n                i++;\n            }\n            numerator *= sign;\n\n            i++; // skip the \'/\'\n\n            int denominator = 0;\n            while (i < n && isdigit(expression[i])) {\n                denominator = denominator * 10 + (expression[i] - \'0\');\n                i++;\n            }\n\n            nus.push_back(numerator);\n            des.push_back(denominator);\n        }\n\n        int deno = des[0];\n        for(int i = 1; i < des.size(); i++){\n            // cout<<nus[i]<<" "<<dis[i]<<endl;\n            deno = LCMFinder(deno, des[i]);\n        }\n\n        for(int i = 0; i < des.size(); i++){\n            nus[i] = nus[i]*(deno/des[i]);\n        }\n\n        int numo = accumulate(nus.begin(), nus.end(), 0);\n        // cout<<numo<<"/"<<dino<<endl;\n\n        if(numo == 0){\n            return "0/1";\n        }\n        int gcd = GCDFinder(numo, deno);\n        numo = numo/gcd;\n        deno = deno/gcd;\n\n        return to_string(numo)+"/"+to_string(deno);\n    }\n};\n```
['C++']