平均绩点上3.9再改名 2023-01-27 20:10 采纳率: 50%
浏览 30
已结题

相同代码在力扣报错在dev不报错

如题

img

img

img

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
 struct node{
     int val;
     struct node* next;
 };
 struct queue{
     struct node* head;
     struct node* end;
 };
 struct queue* iniqueue(){
     struct queue* q=( struct queue*)malloc(sizeof( struct queue));
     q->head=q->end=(struct node*)malloc(sizeof(struct node));
     q->head->next=NULL;
     return q;
 }
 struct node*  addqueue(struct queue* q,int x){
    struct node *s=(struct node*)malloc(sizeof(struct node));
    s->val=x;
    s->next=NULL;
    q->end->next=s;
    q->end=s;
    return s;
 }
 void dequeue(struct queue* q){
     if(q->head->next==NULL)return;
     struct node* s=q->head->next;
     q->head->next=s->next;
     free(s);
     s=NULL;
     return;
 }
 int max(int a[],int k){
     int s;
     for(int i=0;i<k;i++){
    if(i==0)s=a[0];
    else if(a[i]>=a[i-1])s=a[i];
     }
     return s;
 }
int* maxSlidingWindow(int* nums, int numsSize, int k, int* returnSize){
    if(k==1)return nums;
    int i=0;
    int n=1;
    int *r=malloc(sizeof(int) * (numsSize - k + 1));
    struct queue*q=iniqueue();
    struct node*f;
    struct node*g;
    while(1){
    if(i==(k-1)){
        f=addqueue(q,*(nums+i));
        break;
    }
    else addqueue(q,*(nums+i));
    i++;
 }
    g=q->head;
    i=0;
    int j=k;
      int a[numsSize-k+1];
      int b[numsSize-k+1];
     int u;
    while(i<(numsSize-k+1)){
     u=0;
     while(1){
     g=g->next;
     a[u]=g->val;
     if(g==f)break;
     u++;
     }
     dequeue(q);
     g=q->head;
     *(r+i)=max(a,k);
     i++;
     while(n){
          f=addqueue(q,*(nums+j));
     j++;
     if(j==(numsSize))n=0;
     }
 }
return r;
}




  • 写回答

1条回答 默认 最新

  • wresource Android领域优质创作者 2023-01-28 07:02
    关注

    这个出错不是程序的问题,是逻辑上的问题,力扣是帮你测试了,说明程序对于越界这块没处理好,dev不检查这些,它只检查语法等层面的错误。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 2月5日
  • 已采纳回答 1月28日
  • 创建了问题 1月27日