c++ 3ms heihei


  • 0
    N
    class Solution {
    public:
        vector<int> constructRectangle(int area) {
    
            vector<int> v;
            float s = sqrt(area);
            if (fabsf(roundf(s) - s) <= 0.00001f) {
                //int
                v.push_back(s);
                v.push_back(s);
    
                return v;
            } else {
                //float
                for(int i=s; i>0; --i){
    
                    if(area%i == 0){
    
                        int half = area/i;
                        int tem;
                        i>half ? :tem = i; i=half; half=tem;
                        v.push_back(i);
                        v.push_back(half);
                        return v;
    
                    }
                }
            }
        }
    
    };
    

Log in to reply
 

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