German Gonzalez-Morris wrote:use a Set, as a HashSet in Java.
You can add a String or a char[], remembering that a char[] is not a String. You do have to iterate the array and add the individual chars to your set.Manish Hatwalne wrote: . . . how do I push string characters in a Set without loop. . . .
No more Blub for me, thank you, Vicar.
Campbell Ritchie wrote:What do you mean by more efficient?
If you mean readable, then your original option loses hands down.
If you mean in terms of memory use, then you are creating multiple String objects and rejecting them.
If you mean in terms of execution speed, then your suggestion runs in quadratic time whereas the other suggestions would run in linear time.
Campbell Ritchie wrote:There is a second loop in line 4 where you are seeking the index of a letter.
Campbell Ritchie wrote:There is a second loop in line 4 where you are seeking the index of a letter.
Consider Paul's rocket mass heater. |