| Author |
Duplicate array element ?
|
kri shan
Ranch Hand
Joined: Apr 08, 2004
Posts: 1300
|
|
|
My array has ccdddeeeettttauu. I want to find which letter position is not in order, in this case letter 'a' and which letter is duplicate(more than one time).
|
 |
Roger Fed
Ranch Hand
Joined: Oct 17, 2010
Posts: 82
|
|
hello,
you must try and think about the ways that will help you to solve this problem , we are here to help you not to provide solution.
|
I Hear I Forget, I See I Remember, I Do I Understand.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
When is a character out of order? If it comes alphabetically before the previous character, right? So compare each character (except the first) to the previous character, and if it's smaller it's out of order.
When is a character a duplicate? If it already was encountered in the String, right? Now, you can't simply compare a character to its previous character to see if it matches, because a String of "tat" still has duplicates. So you need to a) compare each character with all characters before or after it (both is not necessary), or b) keep track of which characters you already encountered and see if the current character is one of those.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Duplicate array element ?
|
|
|