테이블 해시 함수

LJM·2023년 8월 28일
0

programmers

목록 보기
85/92

https://school.programmers.co.kr/learn/courses/30/lessons/147354

import java.util.*;

class Solution {
    public int solution(int[][] data, int col, int row_begin, int row_end) {
        int result = 0;

        // 커스텀 정렬
        Arrays.sort(data, (a, b) -> {
            if (a[col - 1] == b[col - 1]) {
                return Integer.compare(b[0], a[0]); // 기본키 내림차순
            }
            return Integer.compare(a[col - 1], b[col - 1]); // col 오름차순
        });

        // S_i 계산 및 XOR
        for (int i = row_begin - 1; i <= row_end - 1; i++) {
            int Si = 0;
            for (int j = 0; j < data[i].length; j++) {
                Si += data[i][j] % (i + 1);
            }
            result ^= Si;
        }

        return result;
    }
}
profile
게임개발자 백엔드개발자

0개의 댓글