Unique number of characters(Hashing)
Problem Statement
Given a string s, your task is to find the total number of unique characters in a string.
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
HashSet<Character> hs = new HashSet<>();
String str = sc.nextLine();
int n = str.length();
for(int i=0;i<n;i++){ //pick char by char
hs.add(str.charAt(i));
}
System.out.println(hs.size());
}
}
No comments:
Post a Comment