Results 1 to 3 of 3
- 11-11-2012, 09:59 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 8
- Rep Power
- 0
- 11-11-2012, 11:12 PM #2
Godlike
- Join Date
- Nov 2012
- Posts
- 195
- Rep Power
- 1
Re: How to find duplicate words in string array?
I will give you 10 notes with a word on it. I want you to find out how many duplicate notes there are. How would you go about solving this problem?
Try doing this with pen and paper. Here's a start:
- get a new big paper to write stuff down (we'll call this paper a HashMap. You see what I did there?)
- read the first note
- if my paper does *not* contain this word, write it down and write 1 behind it
- if my paper *does* contain this word, take the number that is behind it and add 1 to that
- read the second note
- if my paper does *not* contain this word, write it down and write 1 behind it
- if my paper *does* contain this word, take the number that is behind it and add 1 to that
- read the third note
- if my paper does *not* contain this word, write it down and write 1 behind it
- if my paper *does* contain this word, take the number that is behind it and add 1 to that
- ....
Now that you have counted all the words, you need to go through the paper again, and see which word is listed more than once.
This is not the only way to do this, this is *a* way... There are many more ways, everybody has his preference.
I know I sound like a pedantic bastard, but it really is the way to get your head around problems like this. Write it down, make drawings, flowcharts, whatever works for you. Then convert it to Java sourcecode one step at a time. Once you get into programming, you will be needing less paper for trivial problems like this.Last edited by SurfMan; 11-11-2012 at 11:16 PM.
- 11-12-2012, 01:16 AM #3
Member
- Join Date
- Nov 2012
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
find index of duplicate words inside string
By onions in forum New To JavaReplies: 9Last Post: 05-09-2012, 03:48 PM -
Need to find a way to print line spacing by words
By technoreject in forum New To JavaReplies: 1Last Post: 07-07-2011, 02:43 PM -
find the link between two words by using wordnet
By STR in forum Advanced JavaReplies: 8Last Post: 07-06-2011, 07:59 AM -
using loop to find duplicate
By gwithey in forum New To JavaReplies: 7Last Post: 03-06-2009, 01:46 PM -
random string are duplicate
By googgoo in forum New To JavaReplies: 3Last Post: 04-03-2008, 10:01 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks