for each character
find next copy of that character
if there is a duplicate
then remove the two characters |
'ABBA'
1. looking at first A, there is another A
=> remove both
2. looking at first B, there is another B
=> remove both
3. at end
string is empty
'AAA'
1. looking at first A, there is another A
=> remove both
2. looking at first A, there is no duplicate
3. at end
string has 'A'
'ABAAKA'
1. looking at first A, there is another A
=> remove both
'BAKA__'
2. looking at first B, there is no duplicate
3. looking at first A, there is a duplicate
=> remove both
'BK____'
4. looking at first K, there is no duplicate
5. at end
string has 'BK'
Do you notice that you have to
move (copy) all remaining array elements left in order to remove something?
Note that only the last occurrence of each character remains (or none).
I need to state that i can only use arrays, not vectors. |
You already have a
std::string
. A string is not a vector nor an array.