public static boolean checkSudoku(int[][] matrix) {
		
		ArrayList<HashSet<Integer>> rowsSets = new ArrayList<HashSet<Integer>>(9);
		ArrayList<HashSet<Integer>> columnsSets = new ArrayList<HashSet<Integer>>(9);
		ArrayList<HashSet<Integer>> subSets = new ArrayList<HashSet<Integer>>(9);
		
		for(int i = 0; i < 9; i++) {
			rowsSets.add(new HashSet<Integer>());
			columnsSets.add(new HashSet<Integer>());
			subSets.add(new HashSet<Integer>());
		}
		
		for(int i = 0; i < 9; i++) {
			for(int j = 0; j < 9; j++) {
				int num = matrix[i][j];
				
				if(num == 0) {
					continue;
				}
				
				if(rowsSets.get(i).contains(num)) {
					return false;
				} else {
					rowsSets.get(i).add(num);
				}
				
				if(columnsSets.get(j).contains(num)) {
					return false;
				} else {
					columnsSets.get(j).add(num);
				}
				
				int subGridi = (i/3)*3 + j/3;
				if(subSets.get(subGridi).contains(num)) {
					return false;
				} else {
					subSets.get(subGridi).add(num);
				}
			}
		}
		
		return true;		
	}