카테고리 없음

[Java]로또의 최고 순위와 최저 순위

혜wony 2022. 5. 12. 09:14

class Solution {
    public int[] solution(int[] lottos, int[] win_nums) {

      
        
    /* 방법1  
      int count = 0;
        int zero=0;
    for(int i : lottos) {
         for(int j : win_nums) {
         if(i == j) count++;
                System.out.println(i+", "+j);

                
         }
         if(i == 0) zero++;
        }
              
        int upResult = 7 - (count + zero) > 6 ? 6 : 7 - (count + zero);
        int downResult = 7 - count > 6 ? 6 : 7 - count;
    int[] answer = {upResult, downResult};
        return answer;  
        
   */
    /*방법 2
   int count = 0;
   int zero=0;
    
    for(int i=0 ; i<lottos.length ; i++){
            for(int j=0; j<win_nums.length ; j++){
                if(lottos[i] == win_nums[j]) count++;
                
            } if(lottos[i] == 0) zero++;
        }
        
        
        int upResult = 7 - (count + zero) > 6 ? 6 : 7 - (count + zero);
        int downResult = 7 - count > 6 ? 6 : 7 - count;
int[] answer = {upResult, downResult};
        return answer;
      
        */
        //방법3 
    int zero=0;
    int count=0;
        
     Map <Integer, Boolean> map = new HashMap<Integer,boolean>;
        
        for(lotto : lottos){
            map.put(lottos,true)
                if(lotto == 0){
                    zero++;
                }
        }
        
        for(win : win_nums){
            if(map.containsKey(win)){
                count++;
            }
        }
                 
        int upResult = 7 - (count + zero) > 6 ? 6 : 7 - (count + zero);
        int downResult = 7 - count > 6 ? 6 : 7 - count;
    
         int[] answer = {upResult, downResult};    
            
        return answer;
      }
}