Leetcode 29. Divide Two Integers

https://leetcode.com/problems/divide-two-integers/

#include<math>
class Solution {
public:
    int divide(int dividend, int divisor) {
        long long int a=dividend,b=divisor;
        int flag=((dividend>0) ^ (divisor>0))? -1:1;
        a /= b;
        a=a>0?a:-a;
        a = a*flag;
        if(a==2147483648)
            return (1<<31)-1;
        else return a;
    }
};
posted @ 2019-05-13 09:53  benda  阅读(94)  评论(0编辑  收藏  举报