[프로그래머스] 카펫

2020. 3. 31. 17:20프로그래머스/LEVEL 2

import java.util.*;
class possible{
    int horizon = 0;
    int vertical = 0;
    
    possible(int horizon,int vertical){
        this.horizon = horizon;
        this.vertical = vertical;
    }
}
class Solution {
    public int[] solution(int brown, int red) {
        int[] answer = new int[2];
        
        List<possible> list = new ArrayList<>();
        
        for(int i=1; i<=red; i++){
            if(red%i==0 && i<=red/i){
                list.add(new possible(i,red/i));
            }
        }
        
      for(int i=0; i<list.size(); i++){
          if(2*(list.get(i).horizon+2) + list.get(i).vertical*2 == brown){
             answer[0] = list.get(i).vertical+2;
             answer[1] = list.get(i).horizon+2;
          }
      }  
        
        
        
        
        return answer;
    }
}