<p>Given a signed 32-bit integer <code>x</code>, return <code>x</code><em> with its digits reversed</em>. If reversing <code>x</code> causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return <code>0</code>.</p>

<p><strong>Assume the environment does not allow you to store 64-bit integers (signed or unsigned).</strong></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> x = 123
<strong>Output:</strong> 321
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> x = -123
<strong>Output:</strong> -321
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> x = 120
<strong>Output:</strong> 21
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>-2<sup>31</sup> &lt;= x &lt;= 2<sup>31</sup> - 1</code></li>
</ul>

class Solution {
public:
    int reverse(int x) {
        /*int i = 0;
        int result = 0;
        while(x != 0) {
            std::cout << "x : " << x << std::endl;
            std::cout << "i : " << i << std::endl;
            std::cout << result << std::endl;
            std::cout << "-----------" << std::endl;
            result += ((x%10) * pow(10, i));
            i++;
            x = x/10;
        }
        std::cout << "x : " << x << std::endl;
        std::cout << "i : " << i << std::endl;
        std::cout << result << std::endl;
        std::cout << "-----------" << std::endl;
        result += ((x%10) * pow(10, i));
        return result;*/
        std::vector<int> digits;
        int result = 0;
        int min = std::numeric_limits<int>::min();
        int max = std::numeric_limits<int>::max();
        while(x!=0) {
            digits.push_back(x%10);
            x = x/10;
        }
        for(int i = 0; i < digits.size(); i++) {
            cout << "i : " << i << endl;
            cout << digits[i] << endl;
            cout << "result : " << result << endl;
            cout << "----------" << endl;
            if(max - (pow(10,digits.size()-1-i) * digits[i]) <= result || min - (pow(10,digits.size()-1-i) * digits[i]) >= result) {
                return 0;
            }
            result += pow(10,digits.size()-1-i) * digits[i];
        }
        return result;
    
    }
};
8800