-
Notifications
You must be signed in to change notification settings - Fork 0
Add files via upload #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| */ | ||
| public class Dictionary { | ||
|
|
||
| static HashMap<String, ArrayList<String>> dictionary = new HashMap<String, ArrayList<String>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have either:
- a comment
- or a good variable name (better)
so we can tell this is a map from prefixes to all words that start with that prefix.
I'd probably call to variable something like "prefixesToWords" but choose something that reads well for you.
|
|
||
| public static void setDictionary(String[] words){ | ||
|
|
||
| for(int i = 0; i < words.length; i++){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: Did you know you could do for(String word : words) {
for the outer loop? This is optional, but many people find it more readable.
| * To change this template file, choose Tools | Templates | ||
| * and open the template in the editor. | ||
| */ | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving auto-generated javadoc in your files is usually bad style :-)
| public class WordGrid { | ||
| int[] Ox = new int[]{-1,0,1}; | ||
| int[] Oy = new int[]{-1,0,1}; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These variable names aren't very explanatory, and especially as O and 0 are easily confused make your code a little hard to read. Can you think of a good name?
I'd use something like "xSteps" or "xNeighbours"
|
|
||
| static HashMap<String, ArrayList<String>> dictionary = new HashMap<String, ArrayList<String>>(); | ||
|
|
||
| public static void setDictionary(String[] words){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: this is a perfectly good data structure, but isn't as space efficient as it could be. Can you do better? This is the sort of follow up question that gets asked at an interview.
If you get stuck you might want to look at https://en.wikipedia.org/wiki/Trie
| } | ||
|
|
||
| /* Given a position (x,y) it generates all its neighbours from a matrix */ | ||
| public ArrayList<Position> neighbors(int x, int y, char[][] chars, String result, boolean[][] visited){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracting a position class is nice design! Can you make it more object oriented? A few ideas:
- maybe pass a Position into this method instead of x,y
- move the neighbours() method to the Position class (you'd have to look again about how you handle visited)
| ArrayList<String> expResult = new ArrayList<String>(); | ||
| expResult.add("sky"); | ||
| expResult.add("key"); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: maybe be consistent with your number of blank lines.
| */ | ||
| public class WordGridTest { | ||
|
|
||
| public WordGridTest() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can leave out the constructor, before and after, they aren't required if you don't use them
| * Test of dfs method, of class WordGrid. | ||
| */ | ||
| @Test | ||
| public void testDfs() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods could be improved by making the name reflect what is being tested, instead of just numbering them. So for example:
testWordGridTraversesWholeTree() or testWordGridIgnoresVisited()
| /** | ||
| * Test of words method, of class WordGrid. | ||
| */ | ||
| @Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done on writing tests
No description provided.