package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/remove-duplicate-letters/
 */
public class Problem316 {
    public String removeDuplicateLetters(String s) {
        char[] chars = s.toCharArray();
        Arrays.sort(chars);
        int set = 0;
        int dup = 0;
        for (char c : chars) {
            int idx = 1 << (c - 97);
            if ((idx & set) > 0) {
                dup |= idx;
            }
            set |= idx;
        }
        System.out.println(Integer.toBinaryString(dup));
        StringBuilder sb = new StringBuilder();
        // TODO:
        return sb.toString();
    }

    public static void main(String[] args) {
        Problem316 prob = new Problem316();
//        System.out.println(prob.removeDuplicateLetters("bcabc")); // abc
//        System.out.println(prob.removeDuplicateLetters("bbcaac")); // bac
        System.out.println(prob.removeDuplicateLetters("cbacdcbc")); // acdb
    }
}

@@ -16,34 +16,8 @@
 e;%0A%0A
-import java.util.Arrays;%0A%0A
 /**%0A
@@ -162,354 +162,8 @@
 ) %7B%0A
-        char%5B%5D chars = s.toCharArray();%0A        Arrays.sort(chars);%0A        int set = 0;%0A        int dup = 0;%0A        for (char c : chars) %7B%0A            int idx = 1 %3C%3C (c - 97);%0A            if ((idx & set) %3E 0) %7B%0A                dup %7C= idx;%0A            %7D%0A            set %7C= idx;%0A        %7D%0A        System.out.println(Integer.toBinaryString(dup));%0A
     
@@ -210,25 +210,8 @@
 ();%0A
-        // TODO:%0A
     

Update problem 316