#unable to get 0 for all alphabets that occur once only

1 messages · Page 1 of 1 (latest)

rigid moat
azure wharfBOT
#

This post has been reserved for your question.

Hey @rigid moat! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

tropic plank
#

How do you need help?

rigid moat
#

hi, Anurg

#

i can't get the return value as 0 when i have String = a b c d e meaning the character only appeared once

tropic plank
#

With spaces?

rigid moat
#

no space

#

//"abcde" -> 0 # no characters repeats more than once

tropic plank
#

And can you explain your logic

rigid moat
#

i use a hashmap to store the key value

#

if the character appear once only, it will but put character and 1

#

otherwise, the 1 will be added with another same character that appeared

#

after the storing, I then iterate over the hashmpa

#

an then if the character is only once thru out and the size is the same as the string size, so the return value should be 0

tropic plank
#

"Size is same as string size" where

rigid moat
#

yes, should be same as string size

tropic plank
#

But you only have to count how many letters occur multiple times

#

Why would it have to be equal to string size

#

And isn't yout total 0

rigid moat
#

the total will change accordingly

#

because some String has multiple same characters

tropic plank
#

Map.size() != string.size()

rigid moat
#

oh ok. let me review

#

still, i can't get it right after changing the size to String size

#

which is Character array length

#

@tropic plank hope you can give me some hints

#

it is late so i think i better go sleep now

tropic plank
#

Same