zoukankan      html  css  js  c++  java
  • leetcode-1203-NOT

    /**
     * Note: The returned array must be malloced, assume caller calls free().
     */
    int* sortItems(int n, int m, int* group, int groupSize, int** beforeItems,
     int beforeItemsSize, int* beforeItemsColSize, int* returnSize){
    
        int ifdone[groupSize];// 记录是否做完
        int* answer = (int *)malloc(sizeof(int) * groupSize);
        int next = 0;
        for(int i = 0;i < groupSize; i++){
        	ifdone[i] = 0;
        	answer[i] = -1;
        }
        // 先循环一遍把0个前置项目的项目给做了
        for(int i = 0; i < n; i++){
        	if (beforeItemsColSize[i] == 0){
        		ifdone[i] = 1;
        		answer[next] = i;
                next +=1;
        	}
        }
        // 一轮一轮的循环,要是哪轮没做新项目,就停止循环开始check
        int flag = 1; // 循环用的flag
        while(flag){
        	flag = 0;
        	for (int i = 0; i < n; i++){
        		if (ifdone[i] == 1)	// 已经做了就跳过
        			continue;
        		int nengzuo = 1;
        		for (int j = 0; j <beforeItemsColSize[i]; j++){
        			if ( ifdone[beforeItems[i][j]] == 0)
        				nengzuo = 0;
        		}
        		if(nengzuo){
        			ifdone[i] = 1;
        			answer[next] = i;
                    next +=1;
        			flag = 1;
        		}
        	}
        }
        //输出检验模块
        //for(int i = 0;i < groupSize; i++){
        //	printf("%d",answer[i]);
        //}
        
        //跳出循环了,检查是否能输出
        if(next == n){
            returnSize[0] = n;
        	return answer;
        }else{
            //printf("not");
            returnSize[0] = 0;
            answer[0] = '
    ';
        	return answer;
        }
    }
    

    没通过,感觉有多种解决方案,但是跟答案不一致就不算通过,不知道是谁的问题。

  • 相关阅读:
    《闯关东》群英传
    这老太太
    URL重写与伪静态
    创建索引视图时提示架构绑定无效,名称必须由两部分构成
    马色见
    食神智多星
    Beautiful Code and Beautiful Software
    /wp64 Compiler Option
    C++的x64移植
    Managing the State Data of MFC Modules
  • 原文地址:https://www.cnblogs.com/gallien/p/14267353.html
Copyright © 2011-2022 走看看