SHARE
TWEET

Untitled

advictoriam Jan 15th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Compressor
  2. {
  3.    public String compressImage(String imageColors)
  4.    {
  5.       String result = "";
  6.       char bufferLetter = imageColors.charAt(0);
  7.       int bufferNumber = 1;
  8.      
  9.       for(int i = 1; i < imageColors.length(); i++)
  10.       {
  11.          if(imageColors.charAt(i) == bufferLetter)
  12.          {
  13.             bufferNumber++;
  14.          }
  15.          else
  16.          {
  17.             result += Integer.toString(bufferNumber);
  18.             result += bufferLetter;
  19.             bufferLetter = imageColors.charAt(i);
  20.             bufferNumber = 1;
  21.          }
  22.       }
  23.       result += Integer.toString(bufferNumber);
  24.       result += bufferLetter;
  25.       return result;
  26.    }
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top