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

相同代码在力扣报错在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日

悬赏问题

  • ¥150 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装