Skip to content

Commit 46da93b

Browse files
author
Tushar Borole
committed
811. Subdomain Visit Count
1 parent c2ffd38 commit 46da93b

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

.idea/workspace.xml

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
|:-----|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------|:-----------------|:---------------------|:-----------|:----------------|:-----------------|:-------------------------------------------------------------------------------|
1010
| 709 | [To Lower Case](https://leetcode.com/problems/to-lower-case/) | [Solution](to_lower_case.js) | 72 ms | 32.1 MB | Easy | | | |
1111
| 1 | [Two Sum](https://leetcode.com/problems/two-sum/) | [two_sum.js](two_sum.js) | 52 ms | 35 MB | Easy | | | |
12+
| 811 | [Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count/) | [subdomain_visit_count.js](subdomain_visit_count.js) | 80 ms | 38.6 MB | Easy | | | |
1213
| 746 | [Min Cost Climbing Stairs](https://leetcode.com/problems/min-cost-climbing-stairs/) [Iterative](min_cost_climbing_stairs.js) | | 56 ms | 34.8 MB | Easy | O(N) | | [:link:](https://www.youtube.com/watch?v=wca05n5PZ-c) |
1314
| 1085 | [Sum of Digits in the Minimum Number](https://leetcode.com/problems/sum-of-digits-in-the-minimum-number/) | [Iterative](sum_of_digits_in_the_minimum_number.js) | 56 ms | 34.9 MB | Easy | | | |
1415
| 674 | [Longest Continuous Increasing Subsequence](https://leetcode.com/problems/longest-continuous-increasing-subsequence/) | [Window Sliding Method](longest_continuous_increasing_subsequence.js) | | 35.1 MB | Easy | | | |

subdomain_visit_count.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @param {string[]} cpdomains
3+
* @return {string[]}
4+
*/
5+
var subdomainVisits = function(cpdomains) {
6+
let map = new Map();
7+
let out = [];
8+
9+
for (let val of cpdomains) {
10+
let [number, domain] = val.split(" ");
11+
number = parseInt(number);
12+
let domainArray = domain.split(".");
13+
for (let i = 0; i < domainArray.length; i++) {
14+
let joinString = domainArray.slice(i, domainArray.length).join(".");
15+
if (!map.has(joinString)) {
16+
map.set(joinString, number);
17+
} else {
18+
const val = map.get(joinString);
19+
map.set(joinString, val + number);
20+
}
21+
}
22+
}
23+
24+
map.forEach((value, key) => {
25+
out.push(`${value} ${key}`);
26+
});
27+
28+
return out;
29+
};
30+
31+
subdomainVisits([
32+
"900 google.mail.com",
33+
"50 yahoo.com",
34+
"1 intel.mail.com",
35+
"5 wiki.org"
36+
]); //?

0 commit comments

Comments
 (0)