GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode/java/811_Subdomain_Visit_Count.java at master · qiyuangong/leetcode

Expand file tree

/

811_Subdomain_Visit_Count.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
22 lines (21 loc) · 931 Bytes
/

811_Subdomain_Visit_Count.java

Copy path

File metadata and controls

22 lines (21 loc) · 931 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution {
public List<String> subdomainVisits(String[] cpdomains) {
// https://leetcode.com/problems/subdomain-visit-count/discuss/121738/C%2B%2BJavaPython-Easy-Understood-Solution
Map<String, Integer> map = new HashMap();
for (String cpdomain : cpdomains) {
int i = cpdomain.indexOf(' ');
int n = Integer.valueOf(cpdomain.substring(0, i));
String domain = cpdomain.substring(i + 1);
for (i = 0; i < domain.length(); ++i) {
if (domain.charAt(i) == '.') {
String d = domain.substring(i + 1);
map.put(d, map.getOrDefault(d, 0) + n);
}
}
map.put(domain, map.getOrDefault(domain, 0) + n);
}
List<String> res = new ArrayList();
for (String domain : map.keySet()) res.add(map.get(domain) + " " + domain);
return res;
}
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.