2022.2.11-leetcode-LCS 02(贪心)
题目;
代码:
//降序
int cmp21(const void *a, const void *b){
return *(int*)b - *(int*)a;
}
int halfQuestions(int* questions, int questionsSize){
int queAnsNum = questionsSize / 2;
int list[1001] = {0};
//打表
for(int i = 0; i < questionsSize; i++){
list[questions[i]]++;
}
int sum = 0;
//贪心
qsort(list,1001, 4, cmp21);
for(int i = 0; i < 1001; i++){
sum += list[i];
if(sum >= queAnsNum){
return i + 1;
}
共有 0 条评论