Skip to content

Commit affebcb

Browse files
add some comments
1 parent 2ce2c73 commit affebcb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

‎InterviewQuestions/src/package1/ConcatenatedWordsII.java

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
import java.util.Set;
1515

1616
public class ConcatenatedWordsII {
17+
/**The 2nd version of solution has these optimizations:
18+
19+
1. It uses a Trie data structure which is a best fit for a problem domain like this, it saves a lot of memory space: instead of using a HashSet, Trie could save all words with the same prefix into the same place. This same location advantage also speeds up the loop up process when searching a particular word/substring.
20+
2. I implemented a remove() and undoRemove() method to mark one word off and on instead of creating a new copy of a HashSet to check every word. This is also a huge performance boost.
21+
22+
This is why it turns a 12 minutes run to 800 ms.*/
1723

1824
public static void main(String...args){
1925
try {

0 commit comments

Comments
 (0)