Say I have two arrays of strings, one word with which their letters are messed up, and the other array is correct spelling The word (to match with the banana in the second array in X Aran).
In addition to the Brutforce method, which compares every syllable of every word in the correct words, the array, rather than the method of starting a simple code to use it?
try it
package com.se; Import java.util.Arrays; Import java.util.Date; Import java.util.HashMap; Import java.util.Map; Public category dosas (public zeros) doTask () {string {] word = {"apple", "banana", "kiwi", "water", "football", "ocean", "sports", "fear" "Frost", "Crocodile", "Rabbit", "Road", "Blockbuster", "Cruise", "Light", "Aba"}; String [] jumbledWords = {"aabann", "wiki", "plepa", "water", "football", "nco", "ex", "fray", "tifers", "arcodisel", "brittb" Dora "," BTBolocker "," urcz "," ILLG "," BAB "}; Maps & lt; String, string & gt; FoundWords = New Hashmop & lt; String, string & gt; (); For (string jwItem: jumbledWords) {char [] wordChars = jwItem.toCharArray (); Arrays.sort (wordChars); For (string w: words) {char [] jwChars = w.toCharArray (); Arrays.sort (jwChars); String str1 = new string (word chars); String str2 = new string (jwChars); If (str1.equalsIgnoreCase (str2)) {foundWords.put (w, jwItem); }}} System.out.println (found word); } Public static zero main (string [] args) {date 1 = new date (); JumbledWords jw = new jouled word (); Jw.doTask (); Date 2 = new date (); System.out.println ("Time taken:" + (date2.getTime () - date1.getTime ())); However this matter is sensitive. UPDATE OK, I have the word = word.toLowerCase () for the insensitive match;
getCharacterList method
UPDATE 2
Removed the conversion in ArrayList, the applicable code
<3d> update
< / P>
There was a slight bug in the previous code. Now the code is correct. It is now more compact.
No comments:
Post a Comment