We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Solution { public: int divide(int dividend, int divisor) { if (dividend == divisor) return 1; unsigned int ans = 0; int sign = 1; // Determine the sign of the result if ((dividend < 0) ^ (divisor < 0)) sign = -1; // Convert both dividend and divisor to positive integers unsigned int n = abs(dividend), d = abs(divisor); // Perform the division while (n >= d) { int count = 0; while (n > (d << (count + 1))) count++; n -= d << count; ans += 1 << count; } // Handle overflow case if (ans == (1 << 31) && sign == 1) return INT_MAX; return sign * ans; } };
The text was updated successfully, but these errors were encountered:
fkdl0048
No branches or pull requests
The text was updated successfully, but these errors were encountered: