Created
July 1, 2017 03:41
-
-
Save 0001vrn/d848741909de5105ecf8a04a760a6162 to your computer and use it in GitHub Desktop.
Run Length Coding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| import java.lang.*; | |
| import java.io.*; | |
| class RunLengthCoding | |
| { | |
| public static void main (String[] args) throws java.lang.Exception | |
| { | |
| // your code goes here | |
| String s = "aaabbbccc"; | |
| LinkedHashMap<Character,Integer> hm=new LinkedHashMap<>(); | |
| for(int i=0;i<s.length();i++) | |
| { | |
| hm.compute(s.charAt(i), (key, val) -> { | |
| if (val == null) { | |
| return 1; | |
| } else { | |
| return val + 1; | |
| } | |
| }); | |
| } | |
| for (Map.Entry<Character, Integer> entry : hm.entrySet()) { | |
| System.out.print(entry.getKey()+""+entry.getValue()); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment