Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaffebcb

Browse files
add some comments
1 parent2ce2c73 commitaffebcb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

‎InterviewQuestions/src/package1/ConcatenatedWordsII.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
importjava.util.Set;
1515

1616
publicclassConcatenatedWordsII {
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
publicstaticvoidmain(String...args){
1925
try {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp