The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
Well, I'd probably put the characters into two Sets and apply a removeAll operation.
But if you have to do it using arrays, here is one way:
Create a boolean array with one boolean value for each possible character value. Set every value to false initially.
Now, for every char in the first string, set the corresponding boolean value to true. Then for every char in the second string, set it to false.
Every char that now has a correspending boolean value of true is one that needs to be in your output.
Out of the head I'd say that this has a complexity of O(n) (where n is the sum of characters in the two strings).
James Carman, President<br />Carman Consulting, Inc.
Originally posted by Steven Bell:
I would make a 'map' out of the first string with a counter for each character.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
Such a structure is typically called a Bag.
Originally posted by Ilja Preuss:
Such a structure is typically called a Bag.
http://jakarta.apache.org/commons/collections/ implements it - James' algorithm would probably be simplified quite a bit by using it.
James Carman, President<br />Carman Consulting, Inc.
Originally posted by James Carman:
Yes it would and if I actually wrote it for my use I would use Commons Collections.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by James Carman:
Oh, that's O(m + n) where m = len(string) and n = len(invalidString)
Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0672324261/ref=jranch-20" target="_blank" rel="nofollow">Ant Developer's Handbook</a>
Originally posted by Kirk Pepperdine:
which is O(n)
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus

"I'm not back." - Bill Harding, Twister
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by David Harkness:
Similarly, an O(xN + y) algorithm is also O(N).
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
In my understanding, that's only true if y is a constant, or if you can prove that y < xN for all N greater some value.
Glenn Murray
Author of Yo Soy Una Vaca De Hoy
Originally posted by Ilja Preuss:
In my understanding, that's only true if y is a constant, or if you can prove that y < xN for all N greater some value.
Yes, I could have been more clear. I had just finished watching Shaun of the Dead and had a difficult time getting my mind into a mathematical frame.Originally posted by Glenn Murray:
I think David meant x and y to be constant, though.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
