每日代碼
至少是其他數兩倍的最大數
. - 力扣(LeetCode)
int dominantIndex(int* nums, int numsSize) {int max_num = 0;int next_max = 0;int pos = 0;for(int i = 0; i < numsSize; i++){if(nums[i] > max_num) {pos = i;next_max = max_num;max_num = nums[i];}else if(nums[i] > next_max){next_max = nums[i];}}if(max_num >= 2*next_max) return pos;else return -1;
}
就是在數組中找到前兩大的數字,else if后面的部分一開始忘了。如果用排序應該是很好的。
C語言碎片知識
在c語言中,一個函數不寫返回值類型,默認的返回類型是( )
A: int B: char C: void D: 都不是
答案:A
II在判斷的時候,A||B,如果A成立,那B就不判斷(執行)了。
-The End-