leetcode-剑指61-OK
language: C
bool isStraight(int* nums, int numsSize){
// 排序
void bubble_sort(int arr[], int size){
int i,j,key;
for (i = 0; i < size ; i++){
for (j = size-1; j>i; j--){
if ( arr[j] < arr[j-1]){
key = arr[j];
arr[j] = arr[j-1];
arr[j-1] =key;
}
}
}
}
bubble_sort(nums,5);
// 找到第一个正树的角标
int firstpositive = 0;
while(nums[firstpositive] ==0)
firstpositive++;
if(firstpositive>=4)
return true;
// 若有重复则false
for (int i = firstpositive; i<4;i++){
if(nums[i] == nums[i+1])
return false;
}
// 相差4或者以内则true
if(nums[4]-nums[firstpositive]<=4)
return true;
return false;
}