@@ -16,16 +16,13 @@ public class Solution {
1616 public  List <List <String >> deleteDuplicateFolder (List <List <String >> paths ) {
1717 duplicates  = new  HashMap <>();
1818 Folder  rootFolder  = new  Folder ("" , null );
19- 
2019 for  (List <String > path  : paths ) {
2120 Folder  folder  = rootFolder ;
2221 for  (String  foldername  : path ) {
2322 folder  = folder .addSubFolder (foldername );
2423 }
2524 }
26- 
2725 rootFolder .calculateHash ();
28- 
2926 for  (Map .Entry <String , ArrayList <Folder >> entry  : duplicates .entrySet ()) {
3027 ArrayList <Folder > foldersWithSameHash  = entry .getValue ();
3128 if  (foldersWithSameHash  != null  && foldersWithSameHash .size () > 1 ) {
@@ -34,46 +31,41 @@ public List<List<String>> deleteDuplicateFolder(List<List<String>> paths) {
3431 }
3532 }
3633 }
37- 
3834 foldersWithRemovedNames  = new  ArrayList <>();
39- 
4035 for  (Map .Entry <String , Folder > entry  : rootFolder .subFolders .entrySet ()) {
4136 Folder  folder  = entry .getValue ();
4237 List <String > path  = new  ArrayList <>();
4338 folder .addPaths (path );
4439 }
45- 
4640 return  foldersWithRemovedNames ;
4741 }
4842
4943 private  class  Folder  {
50-  public  String  name ;
51-  public  Map <String , Folder > subFolders ;
52-  public  Folder  parent ;
53-  public  String  folderHash ;
44+  private  String  name ;
45+  private  Map <String , Folder > subFolders ;
46+  private  Folder  parent ;
47+  private  String  folderHash ;
5448
55-  public  Folder (String  folderName , Folder  parentFolder ) {
49+  private  Folder (String  folderName , Folder  parentFolder ) {
5650 name  = folderName ;
5751 subFolders  = new  HashMap <>();
5852 folderHash  = "" ;
5953 parent  = parentFolder ;
6054 }
6155
62-  public  Folder  addSubFolder (String  foldername ) {
56+  private  Folder  addSubFolder (String  foldername ) {
6357 Folder  subFolder  = subFolders .get (foldername );
6458 if  (subFolder  == null ) {
6559 subFolder  = new  Folder (foldername , this );
6660 subFolders .put (foldername , subFolder );
6761 }
68- 
6962 return  subFolder ;
7063 }
7164
72-  public  void  calculateHash () {
65+  private  void  calculateHash () {
7366 List <String > subFolderNames  = new  ArrayList <>(subFolders .keySet ());
7467 Collections .sort (subFolderNames );
7568 StringBuilder  builder  = new  StringBuilder ();
76- 
7769 for  (String  foldername  : subFolderNames ) {
7870 Folder  folder  = subFolders .get (foldername );
7971 folder .calculateHash ();
@@ -85,7 +77,6 @@ public void calculateHash() {
8577 builder .append (')' );
8678 }
8779 }
88- 
8980 folderHash  = builder .toString ();
9081 if  (folderHash .length () > 0 ) {
9182 ArrayList <Folder > duplicateFolders  =
@@ -94,11 +85,10 @@ public void calculateHash() {
9485 }
9586 }
9687
97-  public  void  addPaths (List <String > parentPath ) {
88+  private  void  addPaths (List <String > parentPath ) {
9889 List <String > currentPath  = new  ArrayList <>(parentPath );
9990 currentPath .add (name );
10091 foldersWithRemovedNames .add (currentPath );
101- 
10292 for  (Map .Entry <String , Folder > entry  : subFolders .entrySet ()) {
10393 Folder  folder  = entry .getValue ();
10494 folder .addPaths (currentPath );
0 commit comments