I can't think of a solution sorry -_-
(I'm thinking to declare a counter variable for each letter of the alphabet but that seems not efficient)
can i get a clue?
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Thomas
11 May 2021, 10:29
instead of a counter variable use an array or a list (maybe a map if that's what you prefer). If you go with an array, Then index 0 is a, 1 is b and so on... If you want to increase count for b, then it's like array[1]++.
The index you easily get using functionality of the List class (open the link and have a look at the methods it offers). As all possible lowercase letters are already in a list, you just have to check if a letter is in that list (contains) and if it is there, you grab the index of that letter (indexOf), that index you then use to increase the count in your results array (at least that's what I do ;) ).
+1
John
11 May 2021, 12:38
Thank you thomas ;) think it`s a good logic that you use the index to increment rather than counting it manually, your solution is good.
0