"Divide Two Integers" errors with "Time Limit Exceeded" in java

Having a hard time understanding why is it failing https://leetcode.com/problems/divide-two-integers/

Here is the code I'm trying to submit

class Solution {
    public int divide(int dividend, int divisor) {
        int sign = ((dividend < 0)^(divisor < 0)) ? -1 : 1; 
        
        double ddend = Math.abs((double)dividend);
        double dsor = Math.abs((double)divisor);
        double result = 0;

        while(ddend >= dsor){
            ddend = ddend - dsor;
            result++;
        }
        
        if(result > Integer.MAX_VALUE)
            return Integer.MAX_VALUE;
        
        return sign * (int)result;
    }
}

I suspect i'm missing something obvious.

Comments (2)