Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public List<List<String>> findDuplicate(String[] paths) {
- // content - paths
- Map<String, List<String>> map = new HashMap<>();
- for (var path : paths) {
- String[] info = path.split(" ");
- String dir = info[0];
- for (int i = 1; i < info.length; i++) {
- String file = info[i];
- int start = file.indexOf('(');
- int end = file.length();
- String content = file.substring(start + 1, end);
- map.putIfAbsent(content, new ArrayList<>());
- map.get(content).add(dir + "/" + file.substring(0, start));
- }
- }
- List<List<String>> ans = new ArrayList<>();
- for (var e : map.entrySet()) {
- if (e.getValue().size() > 1) {
- ans.add(e.getValue());
- }
- }
- return ans;
- }
- }
- Close
- umpkf1234
- umpkf1234
- Nov 05, 2022 22:03
- Details
- Solution
- Java
- Runtime
- 9 ms
- Beats
- 72.82%
- Memory
- 45.9 MB
- Beats
- 55.57%
- Click to check the distribution chart
- Notes
- Write your notes here
- Related Tags
- Select tags
- 0/5
- class Solution {
- public int countWords(String[] words1, String[] words2) {
- if (words1.length > words2.length) {
- return countWords(words2, words1);
- }
- Map<String, Integer> map = new HashMap<>();
- for (int i = 0; i < words1.length; i++) {
- map.putIfAbsent(words1[i], 0);
- map.put(words1[i], map.get(words1[i]) + 1);
- }
- int ans = 0;
- for (int i = 0; i < words2.length; i++) {
- if (map.containsKey(words2[i]) && map.get(words2[i]) < 2) {
- map.put(words2[i], map.get(words2[i]) - 1);
- }
- }
- for (var e : map.entrySet()) {
- if (e.getValue() == 0) {
- ans++;
- }
- }
- return ans;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement