Baiduテスト筆記試験:除草

int numberOfDays(int numOfPlants,int[] plantsHeight){
		int temp=0;
		int days=0;
		int surplus=numOfPlants;
		boolean[] boo=new boolean[numOfPlants];
		boolean flag=true;
		while(flag){
			int left=plantsHeight[0];
			int right=0;
			for(int i=1;i<numOfPlants;i++){
				if(boo[i]==false){
				right=plantsHeight[i];
				if(right>left){
					boo[i]=true;
					flag=false;
					surplus--;
				}
				left=right;
				}
			}
			if(!flag) {
				days++;
				flag=true;
			}else{
				break;
			}
			
			if (surplus!=1) days++;	
		}
		return days;
	}


int numberOfDays(int numOfPlants,int[] plantsHeight){
		int temp=0;
		int days=0;
		int surplus=numOfPlants;
		boolean[] boo=new boolean[numOfPlants];
		boolean flag=true;
		while(flag){
			int left=plantsHeight[0];
			int right=0;
			for(int i=1;i<numOfPlants;i++){
				if(boo[i]==false){
				right=plantsHeight[i];
				if(right>left){
					boo[i]=true;
					flag=false;
					surplus--;
				}
				left=right;
				}
			}
			if(!flag) {
				days++;
				flag=true;
			}else{
				break;
			}
			
			if (surplus!=1) days++;	
		}
		return days;
	}



おすすめ

転載: blog.csdn.net/m0_37541228/article/details/77943072