Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Unique number of characters(Hashing)

Tags: number unique

 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);
        HashSetCharacter> hs = new HashSet();
        String str = sc.nextLine();
        int n = str.length();
        for(int i=0;in;i++){ //pick char by char 
            hs.add(str.charAt(i));
        }
        System.out.println(hs.size());
    }
}


This post first appeared on Newtoncoder, please read the originial post: here

Share the post

Unique number of characters(Hashing)

×

Subscribe to Newtoncoder

Get updates delivered right to your inbox!

Thank you for your subscription

×