@@ -52,32 +52,34 @@ If the file content is very large (GB level), how will you modify your solution?
52
52
*/
53
53
public class _609 {
54
54
55
- public List <List <String >>findDuplicate (String []paths ) {
56
- Map <String ,List <String >>map =new HashMap <>();//key is the file content, value is the list of directories that has this directory/file
57
- for (String path :paths ) {
58
- String []dirAndFiles =path .split (" " );
59
- for (int i =1 ;i <dirAndFiles .length ;i ++) {
60
- String content =dirAndFiles [i ].substring (dirAndFiles [i ].indexOf ("(" ) +1 ,dirAndFiles [i ].indexOf (")" ));
61
- if (!map .containsKey (content )) {
62
- map .put (content ,new ArrayList <>());
55
+ public static class Solution1 {
56
+ public List <List <String >>findDuplicate (String []paths ) {
57
+ Map <String ,List <String >>map =new HashMap <>();//key is the file content, value is the list of directories that has this directory/file
58
+ for (String path :paths ) {
59
+ String []dirAndFiles =path .split (" " );
60
+ for (int i =1 ;i <dirAndFiles .length ;i ++) {
61
+ String content =dirAndFiles [i ].substring (dirAndFiles [i ].indexOf ("(" ) +1 ,dirAndFiles [i ].indexOf (")" ));
62
+ if (!map .containsKey (content )) {
63
+ map .put (content ,new ArrayList <>());
64
+ }
65
+ List <String >dirs =map .get (content );
66
+ dirs .add (dirAndFiles [0 ] +"/" +dirAndFiles [i ].substring (0 ,dirAndFiles [i ].indexOf ("(" )));
67
+ map .put (content ,dirs );
63
68
}
64
- List <String >dirs =map .get (content );
65
- dirs .add (dirAndFiles [0 ] +"/" +dirAndFiles [i ].substring (0 ,dirAndFiles [i ].indexOf ("(" )));
66
- map .put (content ,dirs );
67
69
}
68
- }
69
70
70
- List <List <String >>result =new ArrayList <>();
71
- for (String content :map .keySet ()) {
72
- if (map .get (content ).size () >1 ) {
73
- List <String >dupFile =new ArrayList <>();
74
- for (String dir :map .get (content )) {
75
- dupFile .add (dir );
71
+ List <List <String >>result =new ArrayList <>();
72
+ for (String content :map .keySet ()) {
73
+ if (map .get (content ).size () >1 ) {
74
+ List <String >dupFile =new ArrayList <>();
75
+ for (String dir :map .get (content )) {
76
+ dupFile .add (dir );
77
+ }
78
+ result .add (dupFile );
76
79
}
77
- result .add (dupFile );
78
80
}
81
+ return result ;
79
82
}
80
- return result ;
81
83
}
82
84
83
85
/**Answers to follow-up questions: