Simple code in Java


  • 0
    P
       public int[] dailyTemperatures(int[] temperatures)
      {
                int[]ar=new int[temperatures.length];
            if(temperatures.length==1)
          {
    	    ar[0]=0;
           }
           else
               {
               for(int x=0;x<temperatures.length;x++)
            {  
               int p=0,q=0;
               for(int y=x+1;y<temperatures.length;y++)
              {
            	if(temperatures[x]<temperatures[y])
            	{
            			ar[x]=Math.abs(y-x);
            			p++;
            			break;
                   }
           }
            if(p==0)
           {
           ar[x]=0;
            }
       }
     }
       return ar;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.