<s>[INST] This problem is from LeetCode:
**Fraction to Decimal**: Given a fraction, return its decimal representation as a string.

If the denominator contains repeating decimals, then the representation is enclosed in parentheses.

**Example:**

Input: `numerator = 1`, `denominator = 2`
Output: `"0.5"`

Input: `numerator = 2`, `denominator = 3`
Output: `"0.(6)"`


Input: `numerator = 4`, `denominator = 99`
Output: `"0.(04)"`

Input: `numerator = 1`, `denominator = 333`
Output: `"0.(003)"`

My initial solution was to use a queue to keep track of remainders that have occurred so far and their corresponding decimal digits. The intuition is that if a remainder has occurred before, then the decimal expansion will start repeating.

Here's my code:
```cpp
class Solution {
public:
    string fractionToDecimal(int numerator, int denominator) {
        // Handle edge case
        if (numerator == 0) return "0";

        string result = "";
        if ((numerator > 0) ^ (denominator > 0)) {
            result += "-";
        }
        // Keep track of the sign
        numerator = abs(numerator);
        denominator = abs(denominator);

        // Integral part
        result += to_string(numerator / denominator);
        int remainder = numerator % denominator;

        // Check remainder is 0, return result
        if (remainder == 0) {
            return result;
        }

        result += ".";

        queue<pair<int, char>> q;
        while (remainder != 0) {
            int digit = (remainder * 10) / denominator;

            remainder = (remainder * 10) % denominator;
            q.push({remainder, (char) ('0' + digit)});

            if (q.size() > 1 && q.front().first == remainder) {
                result += "(";
                while (!q.empty()) {
                    result += q.front().second;
                    q.pop();
                }
                result += ")";
                break;
            }
        }

        return result;
    }
};
```
This code works fine but I realize I need to optimize it. My current code checks if the front of the queue is equal to the remainder by peeking into the queue and running a while loop. This is inefficient.

Is there a way to improve my current solution so that the loop can break immediately after a repeated remainder is detected?[/INST]