Skip to content

2716. Minimize String Length

  • Time: $O(n)$
  • Space: $O(n)$
1
2
3
4
5
6
class Solution {
 public:
  int minimizedStringLength(string s) {
    return unordered_set(s.begin(), s.end()).size();
  }
};
1
2
3
4
5
class Solution {
  public int minimizedStringLength(String s) {
    return new HashSet<>(Arrays.asList(s.split(""))).size();
  }
}
1
2
3
class Solution:
  def minimizedStringLength(self, s: str) -> int:
    return len({*s})