Leetcode-Remove Duplicate Letters(Java)

Question:

Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.

Example:
Given “bcabc”
Return “abc”

Given “cbacdcbc”
Return “acdb”

Thinking:

Record the times characters emerges in the list and check from left to right.Record the smallest character postion of the list until find the unique character, then delete the bigger characters before smallest one and delete smallest from the rest of list.

Solution:

public String removeDuplicateLetters(String s) {
    int[] count = new int[26];
    int smallest = 0;
    if (s.length() == 0)    return "";
    for (char c: s.toCharArray())    count[c-'a']++;
    for (int i = 0; i < s.length(); i++){
        if (s.charAt(i) < s.charAt(smallest))    smallest = i;
        if (--count[s.charAt(i) - 'a'] == 0)    break;
    }
    return s.charAt(smallest) + removeDuplicateLetters(s.substring(smallest+1).replaceAll(s.charAt(smallest)+"", ""));
}