문제풀이/구현

[JAVA] [구현] Pro 테이블 해시 함수

승무_ 2023. 7. 11. 10:07

문제

https://school.programmers.co.kr/learn/courses/30/lessons/147354?language=java 

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

코드

import java.util.*;

class Solution {
    public int solution(int[][] data, int col, int row_begin, int row_end) {
        int answer = 0;
        
        Arrays.sort(data, (o1,o2) -> {
            return o1[col-1]==o2[col-1] ? o2[0]-o1[0] : o1[col-1]-o2[col-1];
        });
        
        
        int[] arr=new int[data.length+1];
        for(int i=row_begin-1; i<row_end; i++){
            int temp=0;
            for(int j=0; j<data[0].length; j++){
                temp+=data[i][j]%(i+1);
            }
            arr[i+1]=temp;
        }
        
        // XOR 연산
        for(int i=row_begin; i<=row_end; i++){
            answer= answer ^ arr[i];    
        }
        
        return answer;
    }
}