/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 每日温度
* @param dailyTemperatures int整型一维数组
* @param dailyTemperaturesLen int dailyTemperatures数组长度
* @return int整型一维数组
* @return int* returnSize 返回数组行数
*/
int* temperatures(int* dailyTemperatures, int dailyTemperaturesLen, int* returnSize ) {
// write code here
int i;
int ii;
int a = 0;
int b = 0;
int* ret_array= (int*)malloc(sizeof(int) * dailyTemperaturesLen);
*returnSize = dailyTemperaturesLen;
for(i = 0;i<dailyTemperaturesLen;i++)
{
a = *(dailyTemperatures+i);
for(ii = i+1;ii<dailyTemperaturesLen;ii++)
{
b = *(dailyTemperatures+ii);
if(a<b)
{
ret_array[i] = ii-i;
break;
}
if(ii == (dailyTemperaturesLen-1))
{
ret_array[i] = 0;
}
}
if(i == (dailyTemperaturesLen-1))
{
ret_array[i] = 0;
}
}
//check
/*
for(i = 0;i<dailyTemperaturesLen;i++)
{
printf("@%d",ret_array[i]);
}
*/
return ret_array;
}
可行!



京公网安备 11010502036488号