Given a string s , remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results. Input: s = "bcabc" Output: "abc" Convert the string to an array of char, and store it in a LinkedHashSet . This will preserve your ordering, and remove duplicates. Something like: class Solution { public String removeDuplicateLetters(String s) { String string = "bcabc"; char[] chars = string.toCharArray(); Arrays.sort(chars); Set<Character> charSet = new LinkedHashSet<Character>(); for (char c : chars) { charSet.add(c); } StringBuilder sb = new StringBuilder(); for (Character character : charSet) { sb.append(character); } System.out.println(sb.toString()); return sb.toString(); } }
Symmetric Key Encryption: Encryption is a process to change the form of any message in order to protect it from reading by anyone. In Symmetric-key encryption the message is encrypted by using a key and the same key is used to decrypt the message which makes it easy to use but less secure. It also requires a safe method to transfer the key from one party to another. Asymmetric Key Encryption: Asymmetric Key Encryption is based on public and private key encryption technique. It uses two different key to encrypt and decrypt the message. It is more secure than symmetric key encryption technique but is much slower. Symmetric Key Encryption Asymmetric Key Encryption It only requires a single key for both encryption and decryption. It requires two key one to encrypt and the other one to decrypt. The size of cipher text is same or smaller than the original plain text. The size of cipher text is same or larger than the original plain text. The encryption process is very fast. The encryption pr...
Coroutines are nothing but lightweight threads. Coroutines provide us an easy way to do synchronous and asynchronous programming. Coroutines allow execution to be suspended and resumed later at some point in the future which is best suited for performing non-blocking operations in the case of multithreading. Coroutines is a lightweight thread because creating coroutines doesn't allocate new threads. Instead, they use predefined thread pools, and smart scheduling. Scheduling is the process of determining which piece of work you will execute next.. Is called on suspending functions. We can suspend and resume the Coroutines while execution. This means we can have a long-running task, which can be executed one by one or which can be executed little-by-little.. We can pause it any number of times and resume it when we are ready again. Advantages/Properties : Run 1 background thread & Multiple Coroutines Light Weight Threads Can run in parallel Can wait for each other Communicate wi...
Comments
Post a Comment