🔥✅Beats 100%✅⏲️🔥|| Easy Simple Approach|| C++
\n\n## \uD83D\uDD0D Intuition\n\nGiven a string like "1/3 - 1/2 + 1/4", our goal is to add these fractions and return a single simplified fraction as the result
\n\n## \uD83D\uDD0D Intuition\n\nGiven a string like `"1/3 - 1/2 + 1/4"`, our goal is to **add** these fractions and return a single simplified fraction as the result. The challenge lies in handling different denominators and maintaining the correct signs for each fraction.\n\n## \uD83D\uDEE0\uFE0F Approach\n\nLet\'s break down the solution step-by-step:\n\n### 1\uFE0F\u20E3 **Initialization**\n- **Variables**:\n  - Start with a numerator (`num = 0`) \uD83E\uDDEE and a denominator (`den = 1`).\n  - Use a `sign` variable to track whether the current fraction is positive or negative.\n\n### 2\uFE0F\u20E3 **Parsing the String**\n- **Step-by-Step**:\n  - Traverse through the string \uD83D\uDCDC, and for each fraction:\n    1. Identify and handle the `+` or `-` signs \u2795\u2796.\n    2. Extract the numerator and denominator of the current fraction.\n\n### 3\uFE0F\u20E3 **Fraction Addition**\n- **Formula**:\n  - Update the cumulative numerator and denominator using:\n    \\[\n    \\text{{new\\_num}} = \\text{{num}} \\times \\text{{currD}} + \\text{{currN}} \\times \\text{{den}}\n    \\]\n    \\[\n    \\text{{new\\_den}} = \\text{{den}} \\times \\text{{currD}}\n    \\]\n  - This ensures we correctly add fractions by finding a common denominator.\n\n### 4\uFE0F\u20E3 **Simplification**\n- **GCD Calculation**:\n  - After processing all fractions, simplify the result by dividing both numerator and denominator by their greatest common divisor (GCD) \uD83D\uDD04.\n  - Ensure the correct placement of negative signs if the result is negative.\n\n### 5\uFE0F\u20E3 **Returning the Result**\n- **Final Touch**:\n  - If the result is negative, make sure the numerator carries the negative sign \u2796 and return the fraction as a string.\n\n## \u23F2\uFE0F Complexity\n\n- **Time Complexity**: \\(O(n)\\) \u23F1\uFE0F\n  - The algorithm processes each character in the string exactly once, so the time complexity is linear with respect to the length of the string.\n  \n- **Space Complexity**: \\(O(1)\\) \uD83D\uDCE6\n  - The space complexity is constant, as we use a fixed number of variables for calculations.\n\n---\n\n## \uD83E\uDDD1\u200D\uD83D\uDCBB Code Implementation\n```cpp\nclass Solution {\npublic:\n    string fractionAddition(string s) {\n        int num = 0;  // \uD83E\uDDEE Initial numerator\n        int den = 1;  // \uD83E\uDDEE Initial denominator\n        int i = 0;  // \uD83D\uDD04 Index for traversing the string\n        bool sign = true;  // \u2795 Assume positive sign initially\n\n        while (i < s.size()) {\n            int currN = 0;  // Numerator of the current fraction\n            int currD = 0;  // Denominator of the current fraction\n            sign = true;  // Reset sign to positive \u2795\n\n            char c = s[i];\n\n            // \uD83C\uDF10 Handle \'+\' or \'-\' signs\n            if (c == \'+\' || c == \'-\') {\n                if (c == \'-\') sign = false;  // Change sign to negative \u2796\n                i++;\n            }\n\n            // \uD83D\uDCDD Extract the numerator\n            int j = i;\n            while (i < s.size() && isdigit(s[i])) {\n                i++;\n            }\n            currN = stoi(s.substr(j, i - j));  // Convert to integer\n\n            if (!sign) currN = -currN;  // Apply sign if needed\n\n            i++;  // Skip the \'/\' symbol\n\n            // \uD83D\uDCDD Extract the denominator\n            j = i;\n            while (i < s.size() && isdigit(s[i])) {\n                i++;\n            }\n            currD = stoi(s.substr(j, i - j));  // Convert to integer\n\n            // \u2795\u2796 Perform the fraction addition\n            num = num * currD + currN * den;\n            den = den * currD;\n        }\n\n        // \uD83D\uDD04 Simplify the fraction\n        int x = __gcd(num, den);\n        num /= x;\n        den /= x;\n\n        // \u2696\uFE0F Ensure correct sign placement\n        if(num < 0 || den < 0) {\n            num = abs(num);\n            den = abs(den);\n            return "-" + to_string(num) + "/" + to_string(den);\n        } else {\n            return to_string(num) + "/" + to_string(den);\n        }\n    }\n};\n```\n\n---\n\n
['C++']