[JAVA] Sqrt and increment until mod 0 / T <= O(N), S : O(1)


  • 0
    J
    class Solution {
        public int[] constructRectangle(int area) {
            int[] result = new int[2];
            int i = (int)Math.ceil(Math.sqrt(area));
            
            while(i < area){
                if(area % i == 0)
                    break;
                i++;
            }
            
            result[0] = i;
            result[1] = area/i;
            
            return result;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.