Saturday, October 4, 2014

tenRun

Ques:For each multiple of 10 in the given array, change all the values following it to be that multiple of 10, until encountering another multiple of 10. So {2, 10, 3, 4, 20, 5} yields {2, 10, 10, 10, 20, 20}.

Ans:
        for(int i=0;i<nums.length;i++){
            if(nums[i]%10==0){
               for(int j=i+1;j<nums.length;j++){
                   if(nums[j]%10!=0){
                       nums[j]=(nums[i]/10)*10;
                      
                   }else break;
               }
             }
        }
        return nums;
    }

No comments:

Post a Comment