题目描述:

image-20250328102405619

解析:根据题目求给定字符串有多少不同的字符

代码:

package March;

import java.util.HashSet;
import java.util.Set;

/**
* @author hxw
* @version 1.0
* @date 2025/3/28 10:12
* @description: 2716. 最小化字符串长度 简单
*/
public class TwentyEight {
public static void main(String[] args) {
System.out.println(Solution.minimizedStringLength("cbbd"));
}
static class Solution {
public static int minimizedStringLength(String s) {
Set<Character> charSet = new HashSet<>();
for (char c : s.toCharArray()) {
charSet.add(c);
}
return charSet.size();
}
}
}